rspec-dnsruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTIyMjVlMDQ1NDE3NDgyYmM2MGNiN2FmNjY3MDQxNTI5Nzc1NDY4MA==
4
+ YTIxNDZhOTdjNmNiNTQ3Y2ZhNDUzODMzZTBjYjQ5NmZmNTM0ZmZjZA==
5
5
  data.tar.gz: !binary |-
6
- YWEyMjhlNjhhNjZmYzgwNzRlZjZmODg2ZGMyMTQ3ZWQ1NTJiZGJjMQ==
6
+ YjU0YThmMDg2YzQ0Mzc1NmFhYjcwYjYyY2FlMmY5MWY0MjIxYmUzZg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Y2Q0MDIxZTMwZDBlZWJkZTVmYjFiYmU5MzZjMzYxOGJiOTNkNDBjZmViYjA3
10
- ZWRiNDkwY2QyNzRjYWNlNGY0OGE0ZTk0ZTNkMWFiM2UzNTg4NmEwMzU3MDMx
11
- Yzc1NTM4OGI2NmQ2YTFjYzY5MjkwY2ZlZjdiYWRiM2ZjMzg5MWY=
9
+ OWVjOGJiZjg2MjIyNTBkOTMyZmFhMDBlYTg4NzU3YWUwN2EzNDI4NWIyZDI4
10
+ MzRiNWU1MDI0ODM2ZTlhYWJlMjdkZWY0NjkzZTQ2N2RhZDEyYTIzNDI4OGQw
11
+ MTE0OWJhYWJjZTM1NjIxZmE1YzdlM2FkMzA5OGE3NzI5YWI0MGQ=
12
12
  data.tar.gz: !binary |-
13
- N2Q0MjZiNjc3NmMyYzY4MWRjZDcwODFjN2JlZWY3Yjg0ZjUzOTE3MDJlZmJk
14
- ZjI1ODFjODIyMzVmMzM5YWMzNjgzNmZhMTQ4MmNlMmQwYTVjZjYzMWFmY2E3
15
- ZmRlNDdkYTYwZjk2ZmFjNzllY2Q4NTIxOGMwMTIzMmEwMzk4MGM=
13
+ NWFmODY3Y2M5YWUzODc4YmM5YjdmYjdiNTFmNDE4NWJmYTllZWJmOTM2NDJm
14
+ OGIyNjgwMWVmMzI4YzM4ZWUxOTRmNDVlODBkNTdmOWUwOGMyNzQ2N2JlMjdm
15
+ OTk2MzA1NjE1YWYyMTQ1MGQ2NTM4YjJhODFjNTk3YjI2ODVkNTI=
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+
3
+ script: "rake travis"
4
+
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  rspec-dnsruby
2
2
  =========
3
+
4
+ [![Build Status](https://travis-ci.org/spotify/rspec-dnsruby.png?branch=master)](https://travis-ci.org/spotify/rspec-dnsruby)
5
+
3
6
  rspec-dnsruby is an rspec plugin for easy DNS testing. It is a fork of rspec-dns and uses dnsruby instead of the standard ruby library.
4
7
 
5
8
  Differences with rspec-dns
@@ -135,7 +138,19 @@ nameserver:
135
138
 
136
139
  If this file is missing Resolv will use the settings in /etc/resolv.conf.
137
140
 
138
- If you need to change the [timeout](http://dnsruby.rubyforge.org/classes/Dnsruby/Resolver.html) you can do so like this:
141
+ The full list of configuration options can be found on the [Dnsruby docs](http://dnsruby.rubyforge.org/classes/Dnsruby/Config.html).
142
+
143
+ ### Configuring connection timeout
144
+
145
+ Connection timeout is to stop waiting for resolver.
146
+ If you want to wait over default timeout `1`,
147
+ you can change the timeout in spec files or spec_helpers like this:
148
+
149
+ ```ruby
150
+ RSpec.configuration.rspec_dns_connection_timeout = 5
151
+ ```
152
+
153
+ alternatively you can specify it in the `config/dns.yml` file:
139
154
 
140
155
  ```yaml
141
156
  nameserver:
@@ -144,14 +159,14 @@ nameserver:
144
159
  timeouts: 3
145
160
  ```
146
161
 
147
- The full list of configuration options can be found on the [Dnsruby docs](http://dnsruby.rubyforge.org/classes/Dnsruby/Config.html).
148
-
149
162
  Contributing
150
163
  ------------
151
164
  1. Fork the project on github
152
165
  2. Create your feature branch
153
166
  3. Open a Pull Request
154
167
 
168
+
169
+
155
170
  License & Authors
156
171
  -----------------
157
172
  - Seth Vargo (sethvargo@gmail.com)
data/Rakefile CHANGED
@@ -1,2 +1,12 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+
7
+ task :default => :travis
8
+ task :travis => [:spec]
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.pattern = 'spec/*/*_spec.rb'
12
+ end
@@ -1,3 +1,7 @@
1
+ RSpec.configure do |c|
2
+ c.add_setting :rspec_dns_connection_timeout, :default => 1
3
+ end
4
+
1
5
  RSpec::Matchers.define :have_dns do
2
6
  match do |dns|
3
7
  @dns = dns
@@ -104,11 +108,12 @@ RSpec::Matchers.define :have_dns do
104
108
 
105
109
  def _records
106
110
  @_records ||= begin
107
- Timeout::timeout(10) do
108
- config = _config || {}
111
+ config = _config || {}
112
+ # Backwards compatible config option for rspec-dnsruby
113
+ query_timeout = config[:timeouts] || RSpec.configuration.rspec_dns_connection_timeout
114
+ Timeout::timeout(query_timeout + 0.2) do
109
115
  resolver = Dnsruby::Resolver.new(config)
110
- # Backwards compatible config option from the version which uses ruby stdlib
111
- resolver.query_timeout = config[:timeouts] if config[:timeouts]
116
+ resolver.query_timeout = query_timeout
112
117
  resolver.query(@dns, Dnsruby::Types.ANY)
113
118
  end
114
119
  rescue Exception => e
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
- s.version = '0.1.0'
2
+ s.version = '0.1.1'
3
3
  s.name = 'rspec-dnsruby'
4
4
  s.authors = ['Alexey Lapitsky', 'Johannes Russek']
5
5
  s.email = 'alexey@spotify.com'
6
6
  s.description = 'Easily test your DNS entries with RSpec'
7
7
  s.summary = 'rspec-dnsruby provides an easy-to-use DSL for testing your DNS records are responding as they should.'
8
- s.homepage = 'https://github.com/vzctl/rspec-dnsruby'
8
+ s.homepage = 'https://github.com/spotify/rspec-dnsruby'
9
9
  s.license = 'Apache 2.0'
10
10
 
11
11
  s.files = `git ls-files`.split($\)
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+ require 'dnsruby'
3
+ require 'resolv'
4
+ require_relative '../../lib/rspec-dnsruby'
5
+
6
+ def stub_records(strings)
7
+ records = strings.map { |s| Dnsruby::RR.new_from_string(s) }
8
+ resolver = Dnsruby::Resolver.new
9
+ Dnsruby::Resolver.stub(:new) do
10
+ yield if block_given?
11
+ resolver
12
+ end
13
+ resolver.stub_chain(:query, :answer).and_return(records)
14
+ end
15
+
16
+ describe 'rspec-dns matchers' do
17
+
18
+ describe '#have_dns' do
19
+ context 'with a sigle record' do
20
+ it 'can evalutate an A record' do
21
+ stub_records(['example.com 86400 A 192.168.100.100'])
22
+
23
+ 'example.com'.should have_dns.with_type('A')
24
+ 'example.com'.should_not have_dns.with_type('TXT')
25
+ 'example.com'.should have_dns.with_type('A').and_address(Resolv::IPv4.create('192.168.100.100'))
26
+ end
27
+
28
+ it 'can evalutate a AAAA record' do
29
+ stub_records(['example.com 86400 AAAA 2001:0002:6c::430'])
30
+
31
+ 'example.com'.should have_dns.with_type('AAAA')
32
+ 'example.com'.should_not have_dns.with_type('A')
33
+ 'example.com'.should have_dns.with_type('AAAA')
34
+ .and_address(Resolv::IPv6.create('2001:0002:6c::430'))
35
+ end
36
+
37
+ it 'can evalutate a CNAME record' do
38
+ stub_records(['www.example.com 300 IN CNAME example.com'])
39
+
40
+ 'example.com'.should have_dns.with_type('CNAME')
41
+ 'example.com'.should_not have_dns.with_type('AAAA')
42
+ 'example.com'.should have_dns.with_type('CNAME').and_name('www.example.com')
43
+ end
44
+
45
+ it 'can evalutate an MX record' do
46
+ stub_records(['example.com. 7200 MX 40 mail.example.com.'])
47
+
48
+ 'example.com'.should have_dns.with_type('MX')
49
+ 'example.com'.should_not have_dns.with_type('CNAME')
50
+ 'example.com'.should have_dns.with_type('MX').and_preference(40)
51
+ 'example.com'.should have_dns.with_type('MX')
52
+ .and_preference(40).and_exchange('mail.example.com')
53
+ 'example.com'.should_not have_dns.with_type('MX')
54
+ .and_preference(30).and_exchange('mail.example.com')
55
+ 'example.com'.should_not have_dns.with_type('MX')
56
+ .and_preference(40).and_exchange('example.com')
57
+ end
58
+
59
+ it 'can evalutate an NS record' do
60
+ stub_records(['sub.example.com. 300 IN NS ns.sub.example.com.'])
61
+
62
+ 'example.com'.should have_dns.with_type('NS')
63
+ 'example.com'.should_not have_dns.with_type('MX')
64
+ 'example.com'.should have_dns.with_type('NS').and_domainname('ns.sub.example.com')
65
+ 'example.com'.should_not have_dns.with_type('NS').and_domainname('sub.example.com')
66
+ end
67
+
68
+ it 'can evalutate a PTR record' do
69
+ stub_records(['ptrs.example.com. 300 IN PTR ptr.example.com.'])
70
+
71
+ '192.168.100.100'.should have_dns.with_type('PTR')
72
+ '192.168.100.100'.should_not have_dns.with_type('MX')
73
+ '192.168.100.100'.should have_dns.with_type('PTR').and_domainname('ptr.example.com')
74
+ '192.168.100.100'.should_not have_dns.with_type('PTR').and_domainname('ptrs.example.com')
75
+ end
76
+
77
+ it 'can evalutate an SOA record' do
78
+ stub_records(['example.com 210 IN SOA ns.example.com a.example.com. 2014030712 60 25 3628800 900'])
79
+
80
+ 'example.com'.should have_dns.with_type('SOA')
81
+ 'example.com'.should_not have_dns.with_type('PTR')
82
+ 'example.com'.should have_dns.with_type('SOA')
83
+ .and_mname('ns.example.com')
84
+ .and_rname('a.example.com')
85
+ .and_serial('2014030712')
86
+ .and_refresh(60)
87
+ .and_retry(25)
88
+ .and_expire(3628800)
89
+ .and_minimum(900)
90
+ 'example.com'.should_not have_dns.with_type('SOA')
91
+ .and_mname('nstest.example.com')
92
+ end
93
+
94
+ it 'can evalutate a TXT record' do
95
+ stub_records(['example.com. 300 IN TXT "v=spf1 a:example.com ~all"'])
96
+
97
+ 'example.com'.should have_dns.with_type('TXT')
98
+ 'example.com'.should_not have_dns.with_type('SOA')
99
+ 'example.com'.should have_dns.with_type('TXT').and_data('v=spf1 a:example.com ~all')
100
+ 'example.com'.should_not have_dns.with_type('TXT').and_data('v=spf2 a:example.com ~all')
101
+ end
102
+ end
103
+
104
+ context 'with changable connection timeout' do
105
+ it 'should timeout within 3 seconds in default' do
106
+ stub_records(['example.com 86400 A 192.168.100.100']) do
107
+ sleep 3
108
+ end
109
+ 'example.com'.should_not have_dns.with_type('A')
110
+ end
111
+
112
+ it 'should not timeout within 3 seconds when timeout is 5' do
113
+ RSpec.configuration.rspec_dns_connection_timeout = 5
114
+ stub_records(['example.com 86400 A 192.168.100.100']) do
115
+ sleep 3
116
+ end
117
+ 'example.com'.should have_dns.with_type('A')
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-dnsruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Lapitsky
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
+ - .travis.yml
63
64
  - Gemfile
64
65
  - LICENSE
65
66
  - README.md
@@ -67,7 +68,9 @@ files:
67
68
  - lib/rspec-dnsruby.rb
68
69
  - lib/rspec-dnsruby/have_dns.rb
69
70
  - rspec-dnsruby.gemspec
70
- homepage: https://github.com/vzctl/rspec-dnsruby
71
+ - spec/rspec-dnsruby/have_dns_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: https://github.com/spotify/rspec-dnsruby
71
74
  licenses:
72
75
  - Apache 2.0
73
76
  metadata: {}
@@ -92,5 +95,7 @@ signing_key:
92
95
  specification_version: 4
93
96
  summary: rspec-dnsruby provides an easy-to-use DSL for testing your DNS records are
94
97
  responding as they should.
95
- test_files: []
98
+ test_files:
99
+ - spec/rspec-dnsruby/have_dns_spec.rb
100
+ - spec/spec_helper.rb
96
101
  has_rdoc: