DNSのテストを素早く回すことができるrspec-dnsというのがあるので紹介する。 これを使えば、DNSを変更するときにだいぶ安心できるはず。
使うもの
- ruby
- rspec
- rspec-dns
どのように書くのか?
次のように update_config
でDNSを指定する。(config/dns.ymlというのを更新するので、なにもやらなければ、config/dns.ymlに記載されているまま)
レコードごとにspecを記載していく。
複数のDNSをテストしたい場合は、 update_config
でDNSを指定していく。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
update_config({ :nameserver => ['8.8.8.8'] }) | |
describe 'github.com' do | |
it { should have_dns.with_type('A').and_address('192.30.252.128') } | |
it { should have_dns.with_type('A').and_address('192.30.252.129') } | |
it { should have_dns.with_type('A').and_address('192.30.252.130') } | |
it { should have_dns.with_type('A').and_address('192.30.252.131') } | |
it { should have_dns.with_type('A').and_address('204.232.175.90') } | |
it { should have_dns.with_type('A').and_address('207.97.227.239') } | |
it { should have_dns.with_type('MX').and_exchange('ASPMX.L.GOOGLE.com' ).and_preference('10') } | |
it { should have_dns.with_type('MX').and_exchange('ALT1.ASPMX.L.GOOGLE.com').and_preference('20') } | |
it { should have_dns.with_type('MX').and_exchange('ALT2.ASPMX.L.GOOGLE.com').and_preference('20') } | |
it { should have_dns.with_type('MX').and_exchange('ASPMX2.GOOGLEMAIL.com' ).and_preference('30') } | |
it { should have_dns.with_type('MX').and_exchange('ASPMX3.GOOGLEMAIL.com' ).and_preference('30') } | |
it { should have_dns.with_type('NS').and_name('ns1.p16.dynect.net') } | |
it { should have_dns.with_type('NS').and_name('ns2.p16.dynect.net') } | |
it { should have_dns.with_type('NS').and_name('ns3.p16.dynect.net') } | |
it { should have_dns.with_type('NS').and_name('ns4.p16.dynect.net') } | |
it { should have_dns.with_type('TXT')\ | |
.and_data('v=spf1 include:_spf.google.com include:_netblocks.zdsys.com include:sendgrid.net include:mailgun.org include:smtp.github.com ~all') } | |
it { should have_dns.with_type('SOA').and_mname('ns1.p16.dynect.net') \ | |
.and_rname('hostmaster.github.com').and_serial('1376705002')\ | |
.and_refresh('3600').and_retry('600').and_expire('604800').and_minimum('60') } | |
end |
実行のやり方
-
git clone
-
% git clone -b example https://github.com/otahi/rspec-dns.git
-
-
move into example directory and run
-
% cd rspec-dns/example
-
% rvm use 1.9.3
-
% bundle install --path=vendor/bundle --binstubs=vendor/
-
% bundle exec rspec -c -f doc
-
どのような出力になるか?
% bundle exec rspec -c -f doc github.com should have the correct dns entries with {:type=>"A", :address=>"192.30.252.128"} should have the correct dns entries with {:type=>"A", :address=>"192.30.252.129"} should have the correct dns entries with {:type=>"A", :address=>"192.30.252.130"} should have the correct dns entries with {:type=>"A", :address=>"192.30.252.131"} should have the correct dns entries with {:type=>"A", :address=>"204.232.175.90"} should have the correct dns entries with {:type=>"A", :address=>"207.97.227.239"} should have the correct dns entries with {:type=>"MX", :exchange=>"ASPMX.L.GOOGLE.com", :preference=>10} should have the correct dns entries with {:type=>"MX", :exchange=>"ALT1.ASPMX.L.GOOGLE.com", :preference=>20} should have the correct dns entries with {:type=>"MX", :exchange=>"ALT2.ASPMX.L.GOOGLE.com", :preference=>20} should have the correct dns entries with {:type=>"MX", :exchange=>"ASPMX2.GOOGLEMAIL.com", :preference=>30} should have the correct dns entries with {:type=>"MX", :exchange=>"ASPMX3.GOOGLEMAIL.com", :preference=>30} should have the correct dns entries with {:type=>"NS", :name=>"ns1.p16.dynect.net"} should have the correct dns entries with {:type=>"NS", :name=>"ns2.p16.dynect.net"} should have the correct dns entries with {:type=>"NS", :name=>"ns3.p16.dynect.net"} should have the correct dns entries with {:type=>"NS", :name=>"ns4.p16.dynect.net"} should have the correct dns entries with {:type=>"TXT", :data=>"v=spf1 include:_spf.google.com include:_netblocks.zdsys.com include:sendgrid.net include:mailgun.org include:smtp.github.com ~all"} should have the correct dns entries with {:type=>"SOA", :mname=>"ns1.p16.dynect.net", :rname=>"hostmaster.github.com", :refresh=>3600, :retry=>600, :expire=>604800, :minimum=>60} Finished in 2.4 seconds 17 examples, 0 failures %