fortio/dnsping

View on GitHub
dnsping.txtar

Summary

Maintainability
Test Coverage
# testscript framework tests for dnsping command line
 
# Basic usage test
!dnsping
!stdout .
stderr 'Exactly 2 arguments expected, got 0'
 
# (short) version
dnsping version
stdout '^dev$'
!stderr .
 
# (long) version
dnsping buildinfo
stdout '^dev go'
stdout 'path fortio.org/dnsping'
!stderr .
 
# bad -q type
!dnsping -q foo www.google.com 8.8.8.8
!stdout .
stderr '\[F\] Invalid -q type name "foo", should be one of'
 
# good -q type
dnsping -c 1 -q aaaa www.google.com 8.8.8.8
stderr 'IN\tAAAA'
stdout '0 errors'
 
# ipv6 server
dnsping -c 1 www.google.com 2001:4860:4860::8888
stderr 'Adding \[] around detected input IPv6 server ip info: \[2001:4860:4860::8888]'
 
# -foo (bad flag)
!dnsping -foo
!stdout .
stderr 'flag provided but not defined: -foo'
 
# basic test
dnsping -c 2 www.google.com 8.8.8.8
stderr 'will query 2 times, sleeping 1s in between, the server 8\.8\.8\.8:53 for A \(1\) record for www\.google\.com\.'
stdout '0 errors \(0.00%\), 2 success.'
 
 
# fixed id
dnsping -loglevel debug -c 1 -fixed-id 42 www.google.com 8.8.8.8
stderr 'id: 42'
 
# sequential id
dnsping -loglevel debug -c 2 -sequential-id www.google.com 8.8.8.8
stderr 'id: 1'
stderr 'id: 2'
 
# error (without plural)
dnsping -c 1 doesnnotexist.fortio.org 8.8.8.8
stdout '1 error \(100.00%\), 0 success.'
stderr 'server error'
!stderr '1: \[]'
 
# json stdout
dnsping -c 1 -json - www.google.com 8.8.8.8
stdout '"HowMany": 1,'
stderr 'Successfully wrote .* bytes of Json data to stdout'
 
# json can't write to file
[unix] chmod 000 notwriteable.json
[unix] !dnsping -c 1 -json notwriteable.json www.google.com 8.8.8.8
[unix] stderr '\[F\] Unable to create notwriteable.json: open notwriteable.json: permission denied'
 
# windows workaround for chmod etc...
[windows] dnsping -c 1 -json notwriteable.json www.google.com 8.8.8.8
 
# how to do this without pkill?
[unix] dnsping www.google.com 8.8.8.8 &
[unix] exec sleep 3
[unix] exec pkill -x dnsping # todo want something like kill %1 instead
[unix] wait
[unix] stderr 'will query until interrupted'
[unix] stdout '0 errors \(0.00%\), [34] success.'
 
# json writing to file
dnsping -c 1 -json ok.json www.google.com 8.8.8.8
stderr 'Successfully wrote .* bytes of Json data to ok\.json'
grep '"Server": "8.8.8.8:53",' ok.json
 
-- notwriteable.json --
empty