dns_mock 0.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 959009b04aab3780b0f571bc7b31ad5c651cf454828c7f65535fdcebe5f6a6ca
4
- data.tar.gz: 6dccffd38d203b4216c940099b1c65ba770c27d811350af2fd5c0841405ff5a0
3
+ metadata.gz: c8c53fb0d7b9cff62a03c843f181b830e6186150d73c2339515f497b5f9558f4
4
+ data.tar.gz: b695d733f4b6c90df3479bc8d5bfb5f4b2d524b602cf02bf3f61b1c8ddd8428a
5
5
  SHA512:
6
- metadata.gz: 150da67d3baefc081928aa4551fe7b6830162a65c174052483ed4529fc259c87213ff45114f6507847513646c96127dca19fd8732c8c06ea3b4416a07e28a631
7
- data.tar.gz: 881c264d38be38328285725a8b13b48c7e82628e5ef786853c4ca9067c67ebfd15e7d83befd8a84b6f4dd89307995ea59cc77dbbf07c2f93cff8565b53a52fbe
6
+ metadata.gz: 8f900aeaad134f70d6b060f8772f97c3913c910064597a659d1bac723e9817dc2fc047054fbb010278139af39778f6b527d3a67d581bc8c6cc0b4a629473062c
7
+ data.tar.gz: 8805e95177e44beb21dc9c6dbece5312e69f30d9709b3e5cd5ac8c8a5fa04fa6fe11abbf3174b6c1326968acf934e3b3f6109112d0fedc101ec7684af8028b8c
data/.codeclimate.yml CHANGED
@@ -7,7 +7,7 @@ checks:
7
7
  plugins:
8
8
  rubocop:
9
9
  enabled: true
10
- channel: rubocop-1-8
10
+ channel: rubocop-1-14
11
11
 
12
12
  reek:
13
13
  enabled: true
data/.reek.yml CHANGED
@@ -21,6 +21,8 @@ detectors:
21
21
  - DnsMock::ServerHelper#start_random_server
22
22
  - DnsMock::ServerHelper#stop_all_running_servers
23
23
  - DnsMock::Server::RecordsDictionaryBuilder#rdns_lookup_prefix
24
+ - DnsMock::ContextGeneratorHelper#random_port_number
25
+ - DnsMock::TestFramework::RSpec::Helper#dns_mock_server
24
26
 
25
27
  ControlParameter:
26
28
  exclude:
@@ -45,3 +47,13 @@ detectors:
45
47
  LongParameterList:
46
48
  exclude:
47
49
  - DnsMock::Server#initialize
50
+ - DnsMock#start_server
51
+
52
+ BooleanParameter:
53
+ exclude:
54
+ - DnsMock::Server#initialize
55
+ - DnsMock#start_server
56
+
57
+ NilCheck:
58
+ exclude:
59
+ - DnsMock::Record::Builder::Mx#build
data/.rubocop.yml CHANGED
@@ -118,6 +118,15 @@ Style/EndlessMethod:
118
118
  Style/HashExcept:
119
119
  Enabled: true
120
120
 
121
+ Style/IfWithBooleanLiteralBranches:
122
+ Enabled: true
123
+
124
+ Style/HashConversion:
125
+ Enabled: true
126
+
127
+ Style/StringChars:
128
+ Enabled: true
129
+
121
130
  Layout/LineLength:
122
131
  Max: 150
123
132
 
@@ -203,6 +212,21 @@ Lint/RedundantDirGlobSort:
203
212
  Lint/UnmodifiedReduceAccumulator:
204
213
  Enabled: true
205
214
 
215
+ Lint/NumberedParameterAssignment:
216
+ Enabled: true
217
+
218
+ Lint/OrAssignmentToConstant:
219
+ Enabled: true
220
+
221
+ Lint/SymbolConversion:
222
+ Enabled: true
223
+
224
+ Lint/TripleQuotes:
225
+ Enabled: true
226
+
227
+ Gemspec/DateAssignment:
228
+ Enabled: true
229
+
206
230
  Performance/AncestorsInclude:
207
231
  Enabled: true
208
232
 
@@ -242,6 +266,15 @@ Performance/MethodObjectAsBlock:
242
266
  Performance/Sum:
243
267
  Enabled: true
244
268
 
269
+ Performance/RedundantEqualityComparisonBlock:
270
+ Enabled: true
271
+
272
+ Performance/RedundantSplitRegexpArgument:
273
+ Enabled: true
274
+
275
+ Performance/MapCompact:
276
+ Enabled: true
277
+
245
278
  RSpec/ExampleLength:
246
279
  Enabled: false
247
280
 
data/CHANGELOG.md CHANGED
@@ -2,6 +2,138 @@
2
2
 
3
3
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
4
 
5
+ ## [1.2.2] - 2021-05-06
6
+
7
+ ### Changed
8
+
9
+ - Updated gem development dependencies
10
+ - Updated rubocop/codeclimate config
11
+ - Updated ci config
12
+
13
+ ## [1.2.1] - 2021-03-23
14
+
15
+ ### Changed
16
+
17
+ - Updated gem development dependencies
18
+ - Updated rubocop/codeclimate config
19
+ - Updated gem documentation
20
+ - Updated tests
21
+
22
+ ## [1.2.0] - 2021-02-04
23
+
24
+ ### Ability to specify MX record priority
25
+
26
+ Added ability to specify custom priority of MX record if it needed. Now it impossible to define null or backup MX records. Please note, if you haven't specified a priority of MX record, it will be assigned automatically. MX records builder is assigning priority with step 10 from first item of defined MX records array.
27
+
28
+ ```ruby
29
+ records = {
30
+ 'example.com' => {
31
+ mx: %w[.:0 mx1.domain.com:10 mx2.domain.com:10 mx3.domain.com] # .:0 - null MX record
32
+ }
33
+ }
34
+
35
+ DnsMock.start_server(records: records)
36
+ ```
37
+
38
+ ```bash
39
+ dig @localhost -p 5300 MX example.com
40
+ ```
41
+
42
+ ```
43
+ ; <<>> DiG 9.10.6 <<>> @localhost -p 5300 MX example.com
44
+
45
+ ;; ANSWER SECTION:
46
+ example.com. 1 IN MX 0 .
47
+ example.com. 1 IN MX 10 mx1.domain.com.
48
+ example.com. 1 IN MX 10 mx2.domain.com.
49
+ example.com. 1 IN MX 40 mx3.domain.com.
50
+
51
+ ;; Query time: 0 msec
52
+ ;; SERVER: 127.0.0.1#5300(127.0.0.1)
53
+ ;; WHEN: Wed Feb 03 20:19:51 EET 2021
54
+ ;; MSG SIZE rcvd: 102
55
+ ```
56
+
57
+ ## [1.1.0] - 2021-02-01
58
+
59
+ ### RSpec native support
60
+
61
+ Added DnsMock helper which can simplify integration with RSpec.
62
+
63
+ ```ruby
64
+ # spec/support/config/dns_mock.rb
65
+ require 'dns_mock/test_framework/rspec'
66
+
67
+ RSpec.configure do |config|
68
+ config.include DnsMock::TestFramework::RSpec::Helper
69
+ end
70
+
71
+ # your awesome first_a_record_spec.rb
72
+ RSpec.describe FirstARecord do
73
+ subject(:service) do
74
+ described_class.call(
75
+ hostname,
76
+ dns_gateway_host: 'localhost',
77
+ dns_gateway_port: dns_mock_server.port
78
+ )
79
+ end
80
+
81
+ let(:hostname) { 'example.com' }
82
+ let(:first_a_record) { '1.2.3.4' }
83
+ let(:records) { { hostname => { a: [first_a_record] } } }
84
+
85
+ before { dns_mock_server.assign_mocks(records) }
86
+
87
+ it { is_expected.to eq(first_a_record) }
88
+ end
89
+ ```
90
+
91
+ ## [1.0.0] - 2021-01-29
92
+
93
+ ### Configurable record not found behaviour
94
+
95
+ Added configurable strategy for record not found case. By default it won't raise an exception when DNS record not found in mocked records dictionary:
96
+
97
+ ```ruby
98
+ DnsMock.start_server(port: 5300)
99
+ ```
100
+
101
+ ```bash
102
+ dig @localhost -p 5300 A example.com
103
+ ```
104
+
105
+ ```
106
+ ; <<>> DiG 9.10.6 <<>> @localhost -p 5300 A example.com
107
+ ;; Got answer:
108
+ ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38632
109
+ ;; flags: rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
110
+ ;; WARNING: recursion requested but not available
111
+
112
+ ;; OPT PSEUDOSECTION:
113
+ ; EDNS: version: 0, flags:; udp: 4096
114
+ ;; QUESTION SECTION:
115
+ ;example.com. IN A
116
+
117
+ ;; Query time: 0 msec
118
+ ;; SERVER: 127.0.0.1#5300(127.0.0.1)
119
+ ;; WHEN: Fri Jan 29 08:21:30 EET 2021
120
+ ;; MSG SIZE rcvd: 40
121
+ ```
122
+
123
+ If you want raise an exception when record not found, just start `DnsMock` with `exception_if_not_found: true` option:
124
+
125
+ ```ruby
126
+ DnsMock.start_server(exception_if_not_found: true)
127
+ ```
128
+
129
+ ### Changed
130
+
131
+ - Updated `DnsMock.start_server`
132
+ - Updated `DnsMock::Server`
133
+ - Updated `DnsMock::Response::Message`
134
+ - Updated `DnsMock::Response::Answer`
135
+ - Updated gem version, readme
136
+
5
137
  ## [0.2.1] - 2021-01-27
6
138
 
7
139
  ### Fixed RDNS lookup representation
data/Gemfile.lock CHANGED
@@ -1,30 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dns_mock (0.2.1)
4
+ dns_mock (1.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.1)
10
- bundler-audit (0.7.0.1)
9
+ ast (2.4.2)
10
+ bundler-audit (0.8.0)
11
11
  bundler (>= 1.2.0, < 3)
12
- thor (>= 0.18, < 2)
12
+ thor (~> 1.0)
13
13
  byebug (11.1.3)
14
14
  childprocess (4.0.0)
15
15
  coderay (1.1.3)
16
16
  colorize (0.8.1)
17
- concurrent-ruby (1.1.7)
17
+ concurrent-ruby (1.1.8)
18
18
  diff-lcs (1.4.4)
19
19
  dnsruby (1.61.5)
20
20
  simpleidn (~> 0.1)
21
21
  docile (1.3.5)
22
- faker (2.15.1)
22
+ faker (2.17.0)
23
23
  i18n (>= 1.6, < 2)
24
- fasterer (0.8.3)
24
+ fasterer (0.9.0)
25
25
  colorize (~> 0.7)
26
26
  ruby_parser (>= 3.14.1)
27
- i18n (1.8.7)
27
+ i18n (1.8.10)
28
28
  concurrent-ruby (~> 1.0)
29
29
  iniparse (1.5.0)
30
30
  json (2.5.1)
@@ -34,7 +34,7 @@ GEM
34
34
  childprocess (>= 0.6.3, < 5)
35
35
  iniparse (~> 1.4)
36
36
  parallel (1.20.1)
37
- parser (3.0.0.0)
37
+ parser (3.0.1.1)
38
38
  ast (~> 2.4.1)
39
39
  pry (0.13.1)
40
40
  coderay (~> 1.1)
@@ -42,16 +42,16 @@ GEM
42
42
  pry-byebug (3.9.0)
43
43
  byebug (~> 11.0)
44
44
  pry (~> 0.13.0)
45
- psych (3.3.0)
45
+ psych (3.3.1)
46
46
  rainbow (3.0.0)
47
47
  rake (13.0.3)
48
- reek (6.0.3)
48
+ reek (6.0.4)
49
49
  kwalify (~> 0.7.0)
50
50
  parser (~> 3.0.0)
51
51
  psych (~> 3.1)
52
52
  rainbow (>= 2.0, < 4.0)
53
- regexp_parser (2.0.3)
54
- rexml (3.2.4)
53
+ regexp_parser (2.1.1)
54
+ rexml (3.2.5)
55
55
  rspec (3.10.0)
56
56
  rspec-core (~> 3.10.0)
57
57
  rspec-expectations (~> 3.10.0)
@@ -65,25 +65,25 @@ GEM
65
65
  rspec-expectations (3.10.1)
66
66
  diff-lcs (>= 1.2.0, < 2.0)
67
67
  rspec-support (~> 3.10.0)
68
- rspec-mocks (3.10.1)
68
+ rspec-mocks (3.10.2)
69
69
  diff-lcs (>= 1.2.0, < 2.0)
70
70
  rspec-support (~> 3.10.0)
71
- rspec-support (3.10.1)
72
- rubocop (1.8.1)
71
+ rspec-support (3.10.2)
72
+ rubocop (1.14.0)
73
73
  parallel (~> 1.10)
74
74
  parser (>= 3.0.0.0)
75
75
  rainbow (>= 2.2.2, < 4.0)
76
76
  regexp_parser (>= 1.8, < 3.0)
77
77
  rexml
78
- rubocop-ast (>= 1.2.0, < 2.0)
78
+ rubocop-ast (>= 1.5.0, < 2.0)
79
79
  ruby-progressbar (~> 1.7)
80
80
  unicode-display_width (>= 1.4.0, < 3.0)
81
- rubocop-ast (1.4.0)
82
- parser (>= 2.7.1.5)
83
- rubocop-performance (1.9.2)
84
- rubocop (>= 0.90.0, < 2.0)
81
+ rubocop-ast (1.5.0)
82
+ parser (>= 3.0.1.1)
83
+ rubocop-performance (1.11.3)
84
+ rubocop (>= 1.7.0, < 2.0)
85
85
  rubocop-ast (>= 0.4.0)
86
- rubocop-rspec (2.1.0)
86
+ rubocop-rspec (2.3.0)
87
87
  rubocop (~> 1.0)
88
88
  rubocop-ast (>= 1.1.0)
89
89
  ruby-progressbar (1.11.0)
@@ -97,7 +97,7 @@ GEM
97
97
  simplecov-html (0.10.2)
98
98
  simpleidn (0.2.1)
99
99
  unf (~> 0.1.4)
100
- thor (1.0.1)
100
+ thor (1.1.0)
101
101
  unf (0.1.4)
102
102
  unf_ext
103
103
  unf_ext (0.0.7.7)
@@ -108,19 +108,19 @@ PLATFORMS
108
108
 
109
109
  DEPENDENCIES
110
110
  bundler (~> 1.16)
111
- bundler-audit (~> 0.7.0.1)
111
+ bundler-audit (~> 0.8.0)
112
112
  dns_mock!
113
- faker (~> 2.15, >= 2.15.1)
114
- fasterer (~> 0.8.3)
113
+ faker (~> 2.17)
114
+ fasterer (~> 0.9.0)
115
115
  overcommit (~> 0.57.0)
116
116
  pry-byebug (~> 3.9)
117
117
  rake (~> 13.0, >= 13.0.3)
118
- reek (~> 6.0, >= 6.0.3)
118
+ reek (~> 6.0, >= 6.0.4)
119
119
  rspec (~> 3.10)
120
120
  rspec-dns (~> 0.1.8)
121
- rubocop (~> 1.8, >= 1.8.1)
122
- rubocop-performance (~> 1.9, >= 1.9.2)
123
- rubocop-rspec (~> 2.1)
121
+ rubocop (~> 1.14)
122
+ rubocop-performance (~> 1.11, >= 1.11.3)
123
+ rubocop-rspec (~> 2.3)
124
124
  simplecov (~> 0.17.1)
125
125
 
126
126
  BUNDLED WITH
data/README.md CHANGED
@@ -16,6 +16,9 @@
16
16
  - [Requirements](#requirements)
17
17
  - [Installation](#installation)
18
18
  - [Usage](#usage)
19
+ - [RSpec](#rspec)
20
+ - [DnsMock RSpec helper](#dnsmock-rspec-helper)
21
+ - [DnsMock RSpec interface](#dnsmock-rspec-interface)
19
22
  - [Contributing](#contributing)
20
23
  - [License](#license)
21
24
  - [Code of Conduct](#code-of-conduct)
@@ -56,13 +59,13 @@ Or install it yourself as:
56
59
  ## Usage
57
60
 
58
61
  ```ruby
59
- # Example of mocked DNS records structure
62
+ # Example of mocked DNS records, please follow this data structure
60
63
  records = {
61
64
  'example.com' => {
62
65
  a: %w[1.1.1.1 2.2.2.2],
63
66
  aaaa: %w[2a00:1450:4001:81e::200e],
64
67
  ns: %w[ns1.domain.com ns2.domain.com],
65
- mx: %w[mx1.domain.com mx2.domain.com],
68
+ mx: %w[mx1.domain.com mx2.domain.com:50], # you can specify host(s) or host(s) with priority, use '.:0' for definition null MX record
66
69
  txt: %w[txt_record_1 txt_record_2],
67
70
  cname: 'some.domain.com',
68
71
  soa: [
@@ -82,10 +85,12 @@ records = {
82
85
  }
83
86
  }
84
87
 
85
- # Main DnsMock interface. records:Hash, port:Integer are an
86
- # optional params. By default creates dns mock server with empty
87
- # records. A free port for server will be randomly assigned in
88
- # the range from 49152 to 65535. Returns current dns mock server
88
+ # Main DnsMock interface
89
+ # records:Hash, port:Integer, exception_if_not_found:Boolean
90
+ # are optional params. By default creates dns mock server with
91
+ # empty records. A free port for server will be randomly assigned
92
+ # in the range from 49152 to 65535, if record not found exception
93
+ # won't raises. Returns current dns mock server
89
94
  dns_mock_server = DnsMock.start_server(records: records) # => DnsMock::Server instance
90
95
 
91
96
  # returns current dns mock server port
@@ -108,6 +113,68 @@ DnsMock.running_servers # => [DnsMock::Server instance]
108
113
  DnsMock.stop_running_servers! # => true
109
114
  ```
110
115
 
116
+ ### RSpec
117
+
118
+ Require this either in your Gemfile or in RSpec's support scripts. So either:
119
+
120
+ ```ruby
121
+ # Gemfile
122
+ group :test do
123
+ gem 'rspec'
124
+ gem 'dns_mock', require: 'dns_mock/test_framework/rspec'
125
+ end
126
+ ```
127
+
128
+ or
129
+
130
+ ```ruby
131
+ # spec/support/config/dns_mock.rb
132
+ require 'dns_mock/test_framework/rspec'
133
+ ```
134
+
135
+ #### DnsMock RSpec helper
136
+
137
+ Just add `DnsMock::TestFramework::RSpec::Helper` if you wanna use shortcut `dns_mock_server` for DnsMock server instance into your `RSpec.describe` blocks:
138
+
139
+ ```ruby
140
+ # spec/support/config/dns_mock.rb
141
+ RSpec.configure do |config|
142
+ config.include DnsMock::TestFramework::RSpec::Helper
143
+ end
144
+ ```
145
+
146
+ ```ruby
147
+ # your awesome first_a_record_spec.rb
148
+ RSpec.describe FirstARecord do
149
+ subject(:service) do
150
+ described_class.call(
151
+ hostname,
152
+ dns_gateway_host: 'localhost',
153
+ dns_gateway_port: dns_mock_server.port
154
+ )
155
+ end
156
+
157
+ let(:hostname) { 'example.com' }
158
+ let(:first_a_record) { '1.2.3.4' }
159
+ let(:records) { { hostname => { a: [first_a_record] } } }
160
+
161
+ before { dns_mock_server.assign_mocks(records) }
162
+
163
+ it { is_expected.to eq(first_a_record) }
164
+ end
165
+ ```
166
+
167
+ #### DnsMock RSpec interface
168
+
169
+ If you won't use `DnsMock::TestFramework::RSpec::Helper` you can use `DnsMock::TestFramework::RSpec::Interface` directly instead:
170
+
171
+ ```ruby
172
+ DnsMock::TestFramework::RSpec::Interface.start_server # creates and runs DnsMock server instance
173
+ DnsMock::TestFramework::RSpec::Interface.stop_server! # stops current DnsMock server instance
174
+ DnsMock::TestFramework::RSpec::Interface.reset_mocks! # resets mocks in current DnsMock server instance
175
+ DnsMock::TestFramework::RSpec::Interface.clear_server! # stops and clears current DnsMock server instance
176
+ ```
177
+
111
178
  ## Contributing
112
179
 
113
180
  Bug reports and pull requests are welcome on GitHub at https://github.com/mocktools/ruby-dns-mock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. Please check the [open tikets](https://github.com/mocktools/ruby-dns-mock/issues). Be shure to follow Contributor Code of Conduct below and our [Contributing Guidelines](CONTRIBUTING.md).
@@ -1,3 +1,5 @@
1
+ version: 2.1
2
+
1
3
  defaults: &defaults
2
4
  working_directory: ~/ruby-dns-mock
3
5
  docker:
@@ -5,6 +7,9 @@ defaults: &defaults
5
7
  environment:
6
8
  CC_TEST_REPORTER_ID: 18fba9e7d6885c48453a80a0f019a60d9ffa3fd80467652a6b3c95fef5ea9a50
7
9
 
10
+ orbs:
11
+ ruby: circleci/ruby@1.1.2
12
+
8
13
  references:
9
14
  restore_bundle_cache: &restore_bundle_cache
10
15
  restore_cache:
@@ -29,7 +34,6 @@ references:
29
34
  curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
30
35
  chmod +x ./cc-test-reporter
31
36
 
32
- version: 2
33
37
  jobs:
34
38
  linters:
35
39
  <<: *defaults
@@ -81,9 +85,28 @@ jobs:
81
85
  command: |
82
86
  ./cc-test-reporter sum-coverage --output - --parts $CIRCLE_NODE_TOTAL coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
83
87
 
88
+ compatibility-with-ruby:
89
+ parameters:
90
+ ruby-version:
91
+ type: string
92
+ docker:
93
+ - image: cimg/ruby:<< parameters.ruby-version >>
94
+ steps:
95
+ - checkout
96
+ - ruby/install-deps:
97
+ bundler-version: '1.16.6'
98
+ with-cache: false
99
+ path: './vendor/custom_bundle'
100
+ - run:
101
+ name: Running compatibility tests
102
+ command: bundle exec rspec
103
+
84
104
  workflows:
85
- version: 2
86
- build:
105
+ build_and_test:
87
106
  jobs:
88
107
  - linters
89
108
  - tests
109
+ - compatibility-with-ruby:
110
+ matrix:
111
+ parameters:
112
+ ruby-version: ["2.6", "2.7", "3.0"]
data/dns_mock.gemspec CHANGED
@@ -32,17 +32,17 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['lib']
33
33
 
34
34
  spec.add_development_dependency 'bundler', '~> 1.16'
35
- spec.add_development_dependency 'bundler-audit', '~> 0.7.0.1'
36
- spec.add_development_dependency 'faker', '~> 2.15', '>= 2.15.1'
37
- spec.add_development_dependency 'fasterer', '~> 0.8.3'
35
+ spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
36
+ spec.add_development_dependency 'faker', '~> 2.17'
37
+ spec.add_development_dependency 'fasterer', '~> 0.9.0'
38
38
  spec.add_development_dependency 'overcommit', '~> 0.57.0'
39
39
  spec.add_development_dependency 'pry-byebug', '~> 3.9'
40
40
  spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
41
- spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.3'
41
+ spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.4'
42
42
  spec.add_development_dependency 'rspec', '~> 3.10'
43
43
  spec.add_development_dependency 'rspec-dns', '~> 0.1.8'
44
- spec.add_development_dependency 'rubocop', '~> 1.8', '>= 1.8.1'
45
- spec.add_development_dependency 'rubocop-performance', '~> 1.9', '>= 1.9.2'
46
- spec.add_development_dependency 'rubocop-rspec', '~> 2.1'
44
+ spec.add_development_dependency 'rubocop', '~> 1.14'
45
+ spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.3'
46
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.3'
47
47
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
48
48
  end
data/lib/dns_mock.rb CHANGED
@@ -4,8 +4,8 @@ require_relative 'dns_mock/core'
4
4
 
5
5
  module DnsMock
6
6
  class << self
7
- def start_server(server = DnsMock::Server, records: {}, port: nil)
8
- server.new(records: records, port: port)
7
+ def start_server(server = DnsMock::Server, records: {}, port: nil, exception_if_not_found: false)
8
+ server.new(records: records, port: port, exception_if_not_found: exception_if_not_found)
9
9
  end
10
10
 
11
11
  def running_servers
@@ -4,18 +4,29 @@ module DnsMock
4
4
  module Record
5
5
  module Builder
6
6
  class Mx < DnsMock::Record::Builder::Base
7
+ include DnsMock::Error::Helper
8
+
9
+ MX_RECORD_REGEX_PATTERN = /\A(.+):(\d+)|(.+)\z/.freeze
7
10
  RECORD_PREFERENCE_STEP = 10
8
11
 
9
12
  def build
10
13
  records_data.map.with_index(1) do |record_data, record_preference|
14
+ record_data, custom_record_preference = parse_mx_record_data(record_data)
11
15
  target_factory.new(
12
16
  record_data: [
13
- record_preference * DnsMock::Record::Builder::Mx::RECORD_PREFERENCE_STEP,
17
+ custom_record_preference&.to_i || record_preference * DnsMock::Record::Builder::Mx::RECORD_PREFERENCE_STEP,
14
18
  record_data
15
19
  ]
16
20
  ).create
17
21
  end
18
22
  end
23
+
24
+ private
25
+
26
+ def parse_mx_record_data(record_data)
27
+ raise_record_context_type_error(:mx, record_data, ::String)
28
+ record_data.scan(DnsMock::Record::Builder::Mx::MX_RECORD_REGEX_PATTERN).flatten.compact
29
+ end
19
30
  end
20
31
  end
21
32
  end
@@ -8,8 +8,9 @@ module DnsMock
8
8
  hash[::Resolv::DNS::Resource::IN.const_get(record_type.upcase)] = record_type
9
9
  end.freeze
10
10
 
11
- def initialize(records)
11
+ def initialize(records, exception_if_not_found)
12
12
  @records = records
13
+ @exception_if_not_found = exception_if_not_found
13
14
  end
14
15
 
15
16
  def build(hostname, record_class)
@@ -19,13 +20,13 @@ module DnsMock
19
20
 
20
21
  private
21
22
 
22
- attr_reader :records, :hostname
23
+ attr_reader :records, :exception_if_not_found, :hostname
23
24
 
24
25
  def record_by_type(record_class)
25
26
  record_type = DnsMock::Response::Answer::REVERSE_TYPE_MAPPER[record_class]
26
27
  found_records = records.dig(hostname.to_s, record_type)
27
- raise DnsMock::Error::RecordNotFound.new(record_type, hostname) unless found_records
28
- found_records
28
+ raise DnsMock::Error::RecordNotFound.new(record_type, hostname) unless found_records || !exception_if_not_found
29
+ Array(found_records)
29
30
  end
30
31
  end
31
32
  end
@@ -3,8 +3,14 @@
3
3
  module DnsMock
4
4
  module Response
5
5
  class Message
6
- def initialize(packet, records, dns_answer = DnsMock::Response::Answer, dns_message = ::Resolv::DNS::Message)
7
- @dns_answer = dns_answer.new(records)
6
+ def initialize(
7
+ packet,
8
+ records,
9
+ exception_if_not_found,
10
+ dns_answer = DnsMock::Response::Answer,
11
+ dns_message = ::Resolv::DNS::Message
12
+ )
13
+ @dns_answer = dns_answer.new(records, exception_if_not_found)
8
14
  @dns_message = dns_message.decode(packet)
9
15
  end
10
16
 
@@ -15,13 +15,15 @@ module DnsMock
15
15
  random_available_port = DnsMock::Server::RandomAvailablePort,
16
16
  thread_class = ::Thread,
17
17
  records: nil,
18
- port: nil
18
+ port: nil,
19
+ exception_if_not_found: false
19
20
  )
20
21
  @socket = socket
21
22
  @records_dictionary_builder = records_dictionary_builder
22
23
  @thread_class = thread_class
23
24
  @records = records_dictionary_builder.call(records || {})
24
25
  @port = port || random_available_port.call
26
+ @exception_if_not_found = exception_if_not_found
25
27
  prepare_server_thread
26
28
  end
27
29
 
@@ -34,7 +36,7 @@ module DnsMock
34
36
  break if packet.size.zero?
35
37
 
36
38
  address, port = addr.values_at(3, 1)
37
- socket.send(DnsMock::Response::Message.new(packet, records).as_binary_string, 0, address, port)
39
+ socket.send(DnsMock::Response::Message.new(packet, records, exception_if_not_found).as_binary_string, 0, address, port)
38
40
  end
39
41
  ensure
40
42
  socket.close
@@ -63,7 +65,7 @@ module DnsMock
63
65
 
64
66
  private
65
67
 
66
- attr_reader :socket, :records_dictionary_builder, :thread_class
68
+ attr_reader :socket, :records_dictionary_builder, :thread_class, :exception_if_not_found
67
69
  attr_accessor :records, :thread
68
70
 
69
71
  def prepare_socket_for_session
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core'
4
+ require_relative '../../dns_mock'
5
+ require_relative './rspec/interface'
6
+ require_relative './rspec/helper'
7
+
8
+ RSpec.configure do |config|
9
+ config.before(:suite) { DnsMock::TestFramework::RSpec::Interface.start_server }
10
+ config.after(:suite) { DnsMock::TestFramework::RSpec::Interface.stop_server! }
11
+ config.after { DnsMock::TestFramework::RSpec::Interface.reset_mocks! }
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './interface'
4
+
5
+ module DnsMock
6
+ module TestFramework
7
+ module RSpec
8
+ module Helper
9
+ def dns_mock_server(**options)
10
+ DnsMock::TestFramework::RSpec::Interface.start_server(**options)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DnsMock
4
+ module TestFramework
5
+ module RSpec
6
+ module Interface
7
+ class << self
8
+ def start_server(**options)
9
+ @dns_mock_server ||= DnsMock.start_server(**options) # rubocop:disable Naming/MemoizedInstanceVariableName
10
+ end
11
+
12
+ def stop_server!
13
+ return unless dns_mock_server
14
+
15
+ dns_mock_server.stop!
16
+ end
17
+
18
+ def reset_mocks!
19
+ return unless dns_mock_server
20
+
21
+ dns_mock_server.reset_mocks!
22
+ end
23
+
24
+ def clear_server!
25
+ @dns_mock_server = nil
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :dns_mock_server
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DnsMock
4
- VERSION = '0.2.1'
4
+ VERSION = '1.2.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,48 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.7.0.1
33
+ version: 0.8.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.7.0.1
40
+ version: 0.8.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faker
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.15'
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 2.15.1
47
+ version: '2.17'
51
48
  type: :development
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
52
  - - "~>"
56
53
  - !ruby/object:Gem::Version
57
- version: '2.15'
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: 2.15.1
54
+ version: '2.17'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: fasterer
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
59
  - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: 0.8.3
61
+ version: 0.9.0
68
62
  type: :development
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
- version: 0.8.3
68
+ version: 0.9.0
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: overcommit
77
71
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +123,7 @@ dependencies:
129
123
  version: '6.0'
130
124
  - - ">="
131
125
  - !ruby/object:Gem::Version
132
- version: 6.0.3
126
+ version: 6.0.4
133
127
  type: :development
134
128
  prerelease: false
135
129
  version_requirements: !ruby/object:Gem::Requirement
@@ -139,7 +133,7 @@ dependencies:
139
133
  version: '6.0'
140
134
  - - ">="
141
135
  - !ruby/object:Gem::Version
142
- version: 6.0.3
136
+ version: 6.0.4
143
137
  - !ruby/object:Gem::Dependency
144
138
  name: rspec
145
139
  requirement: !ruby/object:Gem::Requirement
@@ -174,54 +168,48 @@ dependencies:
174
168
  requirements:
175
169
  - - "~>"
176
170
  - !ruby/object:Gem::Version
177
- version: '1.8'
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: 1.8.1
171
+ version: '1.14'
181
172
  type: :development
182
173
  prerelease: false
183
174
  version_requirements: !ruby/object:Gem::Requirement
184
175
  requirements:
185
176
  - - "~>"
186
177
  - !ruby/object:Gem::Version
187
- version: '1.8'
188
- - - ">="
189
- - !ruby/object:Gem::Version
190
- version: 1.8.1
178
+ version: '1.14'
191
179
  - !ruby/object:Gem::Dependency
192
180
  name: rubocop-performance
193
181
  requirement: !ruby/object:Gem::Requirement
194
182
  requirements:
195
183
  - - "~>"
196
184
  - !ruby/object:Gem::Version
197
- version: '1.9'
185
+ version: '1.11'
198
186
  - - ">="
199
187
  - !ruby/object:Gem::Version
200
- version: 1.9.2
188
+ version: 1.11.3
201
189
  type: :development
202
190
  prerelease: false
203
191
  version_requirements: !ruby/object:Gem::Requirement
204
192
  requirements:
205
193
  - - "~>"
206
194
  - !ruby/object:Gem::Version
207
- version: '1.9'
195
+ version: '1.11'
208
196
  - - ">="
209
197
  - !ruby/object:Gem::Version
210
- version: 1.9.2
198
+ version: 1.11.3
211
199
  - !ruby/object:Gem::Dependency
212
200
  name: rubocop-rspec
213
201
  requirement: !ruby/object:Gem::Requirement
214
202
  requirements:
215
203
  - - "~>"
216
204
  - !ruby/object:Gem::Version
217
- version: '2.1'
205
+ version: '2.3'
218
206
  type: :development
219
207
  prerelease: false
220
208
  version_requirements: !ruby/object:Gem::Requirement
221
209
  requirements:
222
210
  - - "~>"
223
211
  - !ruby/object:Gem::Version
224
- version: '2.1'
212
+ version: '2.3'
225
213
  - !ruby/object:Gem::Dependency
226
214
  name: simplecov
227
215
  requirement: !ruby/object:Gem::Requirement
@@ -244,7 +232,6 @@ executables: []
244
232
  extensions: []
245
233
  extra_rdoc_files: []
246
234
  files:
247
- - ".circleci/config.yml"
248
235
  - ".codeclimate.yml"
249
236
  - ".github/BRANCH_NAMING_CONVENTION.md"
250
237
  - ".github/ISSUE_TEMPLATE/bug_report.md"
@@ -269,6 +256,7 @@ files:
269
256
  - Rakefile
270
257
  - bin/console
271
258
  - bin/setup
259
+ - circle.yml
272
260
  - dns_mock.gemspec
273
261
  - lib/dns_mock.rb
274
262
  - lib/dns_mock/core.rb
@@ -304,6 +292,9 @@ files:
304
292
  - lib/dns_mock/server.rb
305
293
  - lib/dns_mock/server/random_available_port.rb
306
294
  - lib/dns_mock/server/records_dictionary_builder.rb
295
+ - lib/dns_mock/test_framework/rspec.rb
296
+ - lib/dns_mock/test_framework/rspec/helper.rb
297
+ - lib/dns_mock/test_framework/rspec/interface.rb
307
298
  - lib/dns_mock/version.rb
308
299
  homepage: https://github.com/mocktools/ruby-dns-mock
309
300
  licenses: