223223 expect ( a_request ( :get , "http://data.iana.org/rdap/ipv6.json" ) ) . to have_been_made . once
224224 expect ( a_request ( :get , "http://data.iana.org/rdap/dns.json" ) ) . to have_been_made . once
225225 end
226+
227+ it 'IP lookup should generate json' do
228+ response = File . new ( "spec/recorded_responses/ip_108_45_128_208.txt" )
229+ stub_request ( :get , "https://rdap.arin.net/registry/ip/108.45.128.208" ) . to_return ( response )
230+
231+ dir = File . join ( @work_dir , "test_lookup_ip_108_45_128_208_200_for_json" )
232+ logger = NicInfo ::Logger . new
233+ logger . data_out = StringIO . new
234+ logger . message_out = StringIO . new
235+ logger . message_level = NicInfo ::MessageLevel ::NO_MESSAGES
236+ config = NicInfo ::Config . new ( dir )
237+ config . logger = logger
238+ config . config [ NicInfo ::BOOTSTRAP ] [ NicInfo ::UPDATE_BSFILES ] = false
239+
240+ args = [ "--json" , "108.45.128.208" ]
241+
242+ expect { NicInfo ::Main . new ( args , config ) . run } . to_not output . to_stdout
243+ expect ( a_request ( :get , "https://rdap.arin.net/registry/ip/108.45.128.208" ) ) . to have_been_made . once
244+
245+ json = JSON . load ( logger . data_out . string )
246+ expect ( json [ "objectClassName" ] ) . to eq ( "ip network" )
247+ end
248+
249+ it 'IP lookup should generate jv' do
250+ response = File . new ( "spec/recorded_responses/ip_108_45_128_208.txt" )
251+ stub_request ( :get , "https://rdap.arin.net/registry/ip/108.45.128.208" ) . to_return ( response )
252+
253+ dir = File . join ( @work_dir , "test_lookup_ip_108_45_128_208_200_for_jv" )
254+ logger = NicInfo ::Logger . new
255+ logger . data_out = StringIO . new
256+ logger . message_out = StringIO . new
257+ logger . message_level = NicInfo ::MessageLevel ::NO_MESSAGES
258+ config = NicInfo ::Config . new ( dir )
259+ config . logger = logger
260+ config . config [ NicInfo ::BOOTSTRAP ] [ NicInfo ::UPDATE_BSFILES ] = false
261+
262+ args = [ "--jv" , "links" , "108.45.128.208" ]
263+
264+ expect { NicInfo ::Main . new ( args , config ) . run } . to_not output . to_stdout
265+ expect ( a_request ( :get , "https://rdap.arin.net/registry/ip/108.45.128.208" ) ) . to have_been_made . once
266+
267+ json = JSON . load ( logger . data_out . string )
268+ expect ( json . length ) . to eq ( 2 )
269+ expect ( json [ 0 ] [ "rel" ] ) . to eq ( "self" )
270+ expect ( json [ 1 ] [ "rel" ] ) . to eq ( "alternate" )
271+ end
272+
226273end
0 commit comments