dns_mock 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +59 -18
- data/.codeclimate.yml +1 -1
- data/.rubocop.yml +36 -0
- data/CHANGELOG.md +51 -2
- data/Gemfile.lock +37 -36
- data/README.md +6 -2
- data/dns_mock.gemspec +9 -9
- data/lib/dns_mock/core.rb +0 -1
- data/lib/dns_mock/server.rb +9 -2
- data/lib/dns_mock/version.rb +1 -1
- metadata +34 -29
- data/lib/dns_mock/server/random_available_port.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bc358120372b309038c4f457483268e58c22ff6e96667bbdf6a398896248749
|
4
|
+
data.tar.gz: d468e04f015a7bd7f5f535454356d2f2affcf3517eb6e0fcc261bc38ddea388d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 318e2a60578aa2a01a0c548fbccd7477b2556f8d0403af15e26d0425e86a10bb2d596616bae764c7ceec8eaa6d89b09437c34bc6ff2ac5cc20890431289177e0
|
7
|
+
data.tar.gz: f74189c81ad853915633bac2ff05f3f48d80a8a52e19198545416b850987fefa8b30475e2db202a8c032ecb7ecf60ab8c4da18645d0c5455620ddee05a0ff73b
|
data/.circleci/config.yml
CHANGED
@@ -1,11 +1,21 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
1
3
|
defaults: &defaults
|
2
4
|
working_directory: ~/ruby-dns-mock
|
3
5
|
docker:
|
4
|
-
- image:
|
6
|
+
- image: cimg/ruby:<< parameters.ruby-version >>
|
5
7
|
environment:
|
6
8
|
CC_TEST_REPORTER_ID: 18fba9e7d6885c48453a80a0f019a60d9ffa3fd80467652a6b3c95fef5ea9a50
|
7
9
|
|
10
|
+
orbs:
|
11
|
+
ruby: circleci/ruby@1.1.3
|
12
|
+
|
8
13
|
references:
|
14
|
+
install_bundler: &install_bundler
|
15
|
+
run:
|
16
|
+
name: Installing Bundler
|
17
|
+
command: gem i bundler -v $(tail -1 Gemfile.lock | tr -d ' ')
|
18
|
+
|
9
19
|
restore_bundle_cache: &restore_bundle_cache
|
10
20
|
restore_cache:
|
11
21
|
keys:
|
@@ -24,66 +34,97 @@ references:
|
|
24
34
|
|
25
35
|
install_codeclimate_reporter: &install_codeclimate_reporter
|
26
36
|
run:
|
27
|
-
name:
|
37
|
+
name: Installing CodeClimate test reporter
|
28
38
|
command: |
|
29
39
|
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
30
40
|
chmod +x ./cc-test-reporter
|
31
41
|
|
32
|
-
version: 2
|
33
42
|
jobs:
|
34
|
-
linters:
|
43
|
+
linters-ruby:
|
44
|
+
parameters:
|
45
|
+
ruby-version:
|
46
|
+
type: string
|
47
|
+
|
35
48
|
<<: *defaults
|
36
49
|
|
37
50
|
steps:
|
38
51
|
- checkout
|
39
52
|
|
53
|
+
- <<: *install_bundler
|
40
54
|
- <<: *restore_bundle_cache
|
41
55
|
- <<: *bundle_install
|
42
56
|
- <<: *save_bundle_cache
|
43
57
|
|
44
58
|
- run:
|
45
|
-
name: Running
|
59
|
+
name: Running Overcommit
|
46
60
|
command: |
|
47
61
|
bundle exec overcommit -s
|
48
62
|
SKIP=AuthorEmail,AuthorName bundle exec overcommit -r
|
49
63
|
|
50
|
-
tests:
|
64
|
+
tests-ruby:
|
65
|
+
parameters:
|
66
|
+
ruby-version:
|
67
|
+
type: string
|
68
|
+
|
51
69
|
<<: *defaults
|
52
70
|
|
53
71
|
steps:
|
54
72
|
- checkout
|
55
73
|
|
74
|
+
- <<: *install_bundler
|
56
75
|
- <<: *restore_bundle_cache
|
57
76
|
- <<: *bundle_install
|
58
77
|
- <<: *save_bundle_cache
|
59
78
|
- <<: *install_codeclimate_reporter
|
60
79
|
|
61
80
|
- run:
|
62
|
-
name: Running
|
81
|
+
name: Running RSpec
|
63
82
|
command: |
|
64
|
-
mkdir /tmp/test-results
|
65
83
|
./cc-test-reporter before-build
|
66
84
|
bundle exec rspec
|
67
85
|
|
68
86
|
- run:
|
69
|
-
name:
|
87
|
+
name: Creating CodeClimate test coverage report
|
70
88
|
command: |
|
71
89
|
./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
|
72
90
|
|
73
|
-
- store_test_results:
|
74
|
-
path: /tmp/test-results
|
75
|
-
|
76
91
|
- store_artifacts:
|
77
|
-
|
78
|
-
|
92
|
+
name: Saving Simplecov coverage artifacts
|
93
|
+
path: ~/ruby-dns-mock/coverage
|
94
|
+
destination: coverage
|
79
95
|
|
80
96
|
- deploy:
|
97
|
+
name: Uploading CodeClimate test coverage report
|
81
98
|
command: |
|
82
99
|
./cc-test-reporter sum-coverage --output - --parts $CIRCLE_NODE_TOTAL coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
|
83
100
|
|
101
|
+
compatibility-ruby:
|
102
|
+
parameters:
|
103
|
+
ruby-version:
|
104
|
+
type: string
|
105
|
+
docker:
|
106
|
+
- image: cimg/ruby:<< parameters.ruby-version >>
|
107
|
+
steps:
|
108
|
+
- checkout
|
109
|
+
- ruby/install-deps:
|
110
|
+
with-cache: false
|
111
|
+
path: './vendor/custom_bundle'
|
112
|
+
- run:
|
113
|
+
name: Running compatibility tests
|
114
|
+
command: bundle exec rspec
|
115
|
+
|
84
116
|
workflows:
|
85
|
-
|
86
|
-
build:
|
117
|
+
build_and_test:
|
87
118
|
jobs:
|
88
|
-
- linters
|
89
|
-
|
119
|
+
- linters-ruby:
|
120
|
+
matrix:
|
121
|
+
parameters:
|
122
|
+
ruby-version: ["2.5"]
|
123
|
+
- tests-ruby:
|
124
|
+
matrix:
|
125
|
+
parameters:
|
126
|
+
ruby-version: ["2.5"]
|
127
|
+
- compatibility-ruby:
|
128
|
+
matrix:
|
129
|
+
parameters:
|
130
|
+
ruby-version: ["2.6", "2.7", "3.0"]
|
data/.codeclimate.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -121,6 +121,21 @@ Style/HashExcept:
|
|
121
121
|
Style/IfWithBooleanLiteralBranches:
|
122
122
|
Enabled: true
|
123
123
|
|
124
|
+
Style/HashConversion:
|
125
|
+
Enabled: true
|
126
|
+
|
127
|
+
Style/StringChars:
|
128
|
+
Enabled: true
|
129
|
+
|
130
|
+
Style/InPatternThen:
|
131
|
+
Enabled: true
|
132
|
+
|
133
|
+
Style/MultilineInPatternThen:
|
134
|
+
Enabled: true
|
135
|
+
|
136
|
+
Style/QuotedSymbols:
|
137
|
+
Enabled: true
|
138
|
+
|
124
139
|
Layout/LineLength:
|
125
140
|
Max: 150
|
126
141
|
|
@@ -218,6 +233,12 @@ Lint/SymbolConversion:
|
|
218
233
|
Lint/TripleQuotes:
|
219
234
|
Enabled: true
|
220
235
|
|
236
|
+
Lint/EmptyInPattern:
|
237
|
+
Enabled: true
|
238
|
+
|
239
|
+
Gemspec/DateAssignment:
|
240
|
+
Enabled: true
|
241
|
+
|
221
242
|
Performance/AncestorsInclude:
|
222
243
|
Enabled: true
|
223
244
|
|
@@ -257,6 +278,15 @@ Performance/MethodObjectAsBlock:
|
|
257
278
|
Performance/Sum:
|
258
279
|
Enabled: true
|
259
280
|
|
281
|
+
Performance/RedundantEqualityComparisonBlock:
|
282
|
+
Enabled: true
|
283
|
+
|
284
|
+
Performance/RedundantSplitRegexpArgument:
|
285
|
+
Enabled: true
|
286
|
+
|
287
|
+
Performance/MapCompact:
|
288
|
+
Enabled: true
|
289
|
+
|
260
290
|
RSpec/ExampleLength:
|
261
291
|
Enabled: false
|
262
292
|
|
@@ -286,3 +316,9 @@ RSpec/MultipleMemoizedHelpers:
|
|
286
316
|
|
287
317
|
RSpec/StubbedMock:
|
288
318
|
Enabled: false
|
319
|
+
|
320
|
+
RSpec/IdenticalEqualityAssertion:
|
321
|
+
Enabled: true
|
322
|
+
|
323
|
+
RSpec/Rails/AvoidSetupHook:
|
324
|
+
Enabled: true
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,55 @@
|
|
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.3.0] - 2021-06-14
|
6
|
+
|
7
|
+
Detecting random available port via OS features. Thanks [@ioquatix](https://github.com/ioquatix) for [suggestion](https://github.com/mocktools/ruby-dns-mock/issues/42) 🚀
|
8
|
+
|
9
|
+
### Removed
|
10
|
+
|
11
|
+
- Removed `DnsMock::Server::RandomAvailablePort`
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
- Updated `DnsMock::Server` class
|
16
|
+
- Updated tests helpers/tests
|
17
|
+
- Updated gem development dependencies
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
- Test coverage issues
|
22
|
+
|
23
|
+
## [1.2.4] - 2021-05-25
|
24
|
+
|
25
|
+
### Changed
|
26
|
+
|
27
|
+
- Updated gem development dependencies
|
28
|
+
- Updated CircleCI config
|
29
|
+
|
30
|
+
## [1.2.3] - 2021-05-11
|
31
|
+
|
32
|
+
### Changed
|
33
|
+
|
34
|
+
- Updated gem development dependencies
|
35
|
+
- Updated CircleCI config
|
36
|
+
|
37
|
+
## [1.2.2] - 2021-05-06
|
38
|
+
|
39
|
+
### Changed
|
40
|
+
|
41
|
+
- Updated gem development dependencies
|
42
|
+
- Updated rubocop/codeclimate config
|
43
|
+
- Updated CircleCI config
|
44
|
+
|
45
|
+
## [1.2.1] - 2021-03-23
|
46
|
+
|
47
|
+
### Changed
|
48
|
+
|
49
|
+
- Updated gem development dependencies
|
50
|
+
- Updated rubocop/codeclimate config
|
51
|
+
- Updated gem documentation
|
52
|
+
- Updated tests
|
53
|
+
|
5
54
|
## [1.2.0] - 2021-02-04
|
6
55
|
|
7
56
|
### Ability to specify MX record priority
|
@@ -11,7 +60,7 @@ Added ability to specify custom priority of MX record if it needed. Now it impos
|
|
11
60
|
```ruby
|
12
61
|
records = {
|
13
62
|
'example.com' => {
|
14
|
-
mx: %w[.:0 mx1.domain.com:10 mx2.domain.com:10 mx3.domain.com]
|
63
|
+
mx: %w[.:0 mx1.domain.com:10 mx2.domain.com:10 mx3.domain.com] # .:0 - null MX record
|
15
64
|
}
|
16
65
|
}
|
17
66
|
|
@@ -119,7 +168,7 @@ DnsMock.start_server(exception_if_not_found: true)
|
|
119
168
|
|
120
169
|
## [0.2.1] - 2021-01-27
|
121
170
|
|
122
|
-
### Fixed
|
171
|
+
### Fixed
|
123
172
|
|
124
173
|
Fixed RDNS lookup representatin for IP address in PTR record feature.
|
125
174
|
|
data/Gemfile.lock
CHANGED
@@ -1,40 +1,41 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dns_mock (1.
|
4
|
+
dns_mock (1.3.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
|
-
bundler-audit (0.
|
10
|
+
bundler-audit (0.8.0)
|
11
11
|
bundler (>= 1.2.0, < 3)
|
12
|
-
thor (
|
12
|
+
thor (~> 1.0)
|
13
13
|
byebug (11.1.3)
|
14
|
-
childprocess (4.
|
14
|
+
childprocess (4.1.0)
|
15
15
|
coderay (1.1.3)
|
16
16
|
colorize (0.8.1)
|
17
|
-
concurrent-ruby (1.1.
|
17
|
+
concurrent-ruby (1.1.9)
|
18
18
|
diff-lcs (1.4.4)
|
19
19
|
dnsruby (1.61.5)
|
20
20
|
simpleidn (~> 0.1)
|
21
|
-
docile (1.
|
22
|
-
faker (2.
|
21
|
+
docile (1.4.0)
|
22
|
+
faker (2.18.0)
|
23
23
|
i18n (>= 1.6, < 2)
|
24
|
-
fasterer (0.
|
24
|
+
fasterer (0.9.0)
|
25
25
|
colorize (~> 0.7)
|
26
26
|
ruby_parser (>= 3.14.1)
|
27
|
-
i18n (1.8.
|
27
|
+
i18n (1.8.10)
|
28
28
|
concurrent-ruby (~> 1.0)
|
29
29
|
iniparse (1.5.0)
|
30
30
|
json (2.5.1)
|
31
31
|
kwalify (0.7.2)
|
32
32
|
method_source (1.0.0)
|
33
|
-
overcommit (0.
|
33
|
+
overcommit (0.58.0)
|
34
34
|
childprocess (>= 0.6.3, < 5)
|
35
35
|
iniparse (~> 1.4)
|
36
|
+
rexml (~> 3.2)
|
36
37
|
parallel (1.20.1)
|
37
|
-
parser (3.0.
|
38
|
+
parser (3.0.1.1)
|
38
39
|
ast (~> 2.4.1)
|
39
40
|
pry (0.13.1)
|
40
41
|
coderay (~> 1.1)
|
@@ -42,16 +43,16 @@ GEM
|
|
42
43
|
pry-byebug (3.9.0)
|
43
44
|
byebug (~> 11.0)
|
44
45
|
pry (~> 0.13.0)
|
45
|
-
psych (3.3.
|
46
|
+
psych (3.3.2)
|
46
47
|
rainbow (3.0.0)
|
47
48
|
rake (13.0.3)
|
48
|
-
reek (6.0.
|
49
|
+
reek (6.0.4)
|
49
50
|
kwalify (~> 0.7.0)
|
50
51
|
parser (~> 3.0.0)
|
51
52
|
psych (~> 3.1)
|
52
53
|
rainbow (>= 2.0, < 4.0)
|
53
|
-
regexp_parser (2.
|
54
|
-
rexml (3.2.
|
54
|
+
regexp_parser (2.1.1)
|
55
|
+
rexml (3.2.5)
|
55
56
|
rspec (3.10.0)
|
56
57
|
rspec-core (~> 3.10.0)
|
57
58
|
rspec-expectations (~> 3.10.0)
|
@@ -69,27 +70,27 @@ GEM
|
|
69
70
|
diff-lcs (>= 1.2.0, < 2.0)
|
70
71
|
rspec-support (~> 3.10.0)
|
71
72
|
rspec-support (3.10.2)
|
72
|
-
rubocop (1.
|
73
|
+
rubocop (1.16.1)
|
73
74
|
parallel (~> 1.10)
|
74
75
|
parser (>= 3.0.0.0)
|
75
76
|
rainbow (>= 2.2.2, < 4.0)
|
76
77
|
regexp_parser (>= 1.8, < 3.0)
|
77
78
|
rexml
|
78
|
-
rubocop-ast (>= 1.
|
79
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
79
80
|
ruby-progressbar (~> 1.7)
|
80
81
|
unicode-display_width (>= 1.4.0, < 3.0)
|
81
|
-
rubocop-ast (1.
|
82
|
-
parser (>=
|
83
|
-
rubocop-performance (1.
|
84
|
-
rubocop (>=
|
82
|
+
rubocop-ast (1.7.0)
|
83
|
+
parser (>= 3.0.1.1)
|
84
|
+
rubocop-performance (1.11.3)
|
85
|
+
rubocop (>= 1.7.0, < 2.0)
|
85
86
|
rubocop-ast (>= 0.4.0)
|
86
|
-
rubocop-rspec (2.
|
87
|
+
rubocop-rspec (2.4.0)
|
87
88
|
rubocop (~> 1.0)
|
88
89
|
rubocop-ast (>= 1.1.0)
|
89
90
|
ruby-progressbar (1.11.0)
|
90
|
-
ruby_parser (3.
|
91
|
-
sexp_processor (~> 4.
|
92
|
-
sexp_processor (4.15.
|
91
|
+
ruby_parser (3.16.0)
|
92
|
+
sexp_processor (~> 4.15, >= 4.15.1)
|
93
|
+
sexp_processor (4.15.3)
|
93
94
|
simplecov (0.17.1)
|
94
95
|
docile (~> 1.1)
|
95
96
|
json (>= 1.8, < 3)
|
@@ -104,24 +105,24 @@ GEM
|
|
104
105
|
unicode-display_width (2.0.0)
|
105
106
|
|
106
107
|
PLATFORMS
|
107
|
-
|
108
|
+
x86_64-darwin-19
|
108
109
|
|
109
110
|
DEPENDENCIES
|
110
|
-
bundler (~>
|
111
|
-
bundler-audit (~> 0.
|
111
|
+
bundler (~> 2.2, >= 2.2.20)
|
112
|
+
bundler-audit (~> 0.8.0)
|
112
113
|
dns_mock!
|
113
|
-
faker (~> 2.
|
114
|
-
fasterer (~> 0.
|
115
|
-
overcommit (~> 0.
|
114
|
+
faker (~> 2.18)
|
115
|
+
fasterer (~> 0.9.0)
|
116
|
+
overcommit (~> 0.58.0)
|
116
117
|
pry-byebug (~> 3.9)
|
117
118
|
rake (~> 13.0, >= 13.0.3)
|
118
|
-
reek (~> 6.0, >= 6.0.
|
119
|
+
reek (~> 6.0, >= 6.0.4)
|
119
120
|
rspec (~> 3.10)
|
120
121
|
rspec-dns (~> 0.1.8)
|
121
|
-
rubocop (~> 1.
|
122
|
-
rubocop-performance (~> 1.
|
123
|
-
rubocop-rspec (~> 2.
|
122
|
+
rubocop (~> 1.16, >= 1.16.1)
|
123
|
+
rubocop-performance (~> 1.11, >= 1.11.3)
|
124
|
+
rubocop-rspec (~> 2.4)
|
124
125
|
simplecov (~> 0.17.1)
|
125
126
|
|
126
127
|
BUNDLED WITH
|
127
|
-
|
128
|
+
2.2.20
|
data/README.md
CHANGED
@@ -17,6 +17,8 @@
|
|
17
17
|
- [Installation](#installation)
|
18
18
|
- [Usage](#usage)
|
19
19
|
- [RSpec](#rspec)
|
20
|
+
- [DnsMock RSpec helper](#dnsmock-rspec-helper)
|
21
|
+
- [DnsMock RSpec interface](#dnsmock-rspec-interface)
|
20
22
|
- [Contributing](#contributing)
|
21
23
|
- [License](#license)
|
22
24
|
- [Code of Conduct](#code-of-conduct)
|
@@ -63,7 +65,7 @@ records = {
|
|
63
65
|
a: %w[1.1.1.1 2.2.2.2],
|
64
66
|
aaaa: %w[2a00:1450:4001:81e::200e],
|
65
67
|
ns: %w[ns1.domain.com ns2.domain.com],
|
66
|
-
mx: %w[mx1.domain.com mx2.domain.com:50], # you can specify host(s) or host(s) with priority
|
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
|
67
69
|
txt: %w[txt_record_1 txt_record_2],
|
68
70
|
cname: 'some.domain.com',
|
69
71
|
soa: [
|
@@ -88,7 +90,9 @@ records = {
|
|
88
90
|
# are optional params. By default creates dns mock server with
|
89
91
|
# empty records. A free port for server will be randomly assigned
|
90
92
|
# in the range from 49152 to 65535, if record not found exception
|
91
|
-
# won't raises.
|
93
|
+
# won't raises. Please note if you specify zero port number,
|
94
|
+
# free port number will be randomly assigned as a server port too.
|
95
|
+
# Returns current dns mock server
|
92
96
|
dns_mock_server = DnsMock.start_server(records: records) # => DnsMock::Server instance
|
93
97
|
|
94
98
|
# returns current dns mock server port
|
data/dns_mock.gemspec
CHANGED
@@ -31,18 +31,18 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ['lib']
|
33
33
|
|
34
|
-
spec.add_development_dependency 'bundler', '~>
|
35
|
-
spec.add_development_dependency 'bundler-audit', '~> 0.
|
36
|
-
spec.add_development_dependency 'faker', '~> 2.
|
37
|
-
spec.add_development_dependency 'fasterer', '~> 0.
|
38
|
-
spec.add_development_dependency 'overcommit', '~> 0.
|
34
|
+
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.20'
|
35
|
+
spec.add_development_dependency 'bundler-audit', '~> 0.8.0'
|
36
|
+
spec.add_development_dependency 'faker', '~> 2.18'
|
37
|
+
spec.add_development_dependency 'fasterer', '~> 0.9.0'
|
38
|
+
spec.add_development_dependency 'overcommit', '~> 0.58.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.
|
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.
|
45
|
-
spec.add_development_dependency 'rubocop-performance', '~> 1.
|
46
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 2.
|
44
|
+
spec.add_development_dependency 'rubocop', '~> 1.16', '>= 1.16.1'
|
45
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.11', '>= 1.11.3'
|
46
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.4'
|
47
47
|
spec.add_development_dependency 'simplecov', '~> 0.17.1'
|
48
48
|
end
|
data/lib/dns_mock/core.rb
CHANGED
data/lib/dns_mock/server.rb
CHANGED
@@ -4,6 +4,8 @@ module DnsMock
|
|
4
4
|
class Server
|
5
5
|
include DnsMock::Error::Helper
|
6
6
|
|
7
|
+
CURRENT_HOST_NAME = 'localhost'
|
8
|
+
CURRENT_HOST_ADDRESS = '127.0.0.1'
|
7
9
|
WARMUP_DELAY = 0.1
|
8
10
|
PACKET_MAX_BYTES_SIZE = 65_535
|
9
11
|
|
@@ -12,7 +14,6 @@ module DnsMock
|
|
12
14
|
def initialize( # rubocop:disable Metrics/ParameterLists
|
13
15
|
socket = ::UDPSocket.new,
|
14
16
|
records_dictionary_builder = DnsMock::Server::RecordsDictionaryBuilder,
|
15
|
-
random_available_port = DnsMock::Server::RandomAvailablePort,
|
16
17
|
thread_class = ::Thread,
|
17
18
|
records: nil,
|
18
19
|
port: nil,
|
@@ -22,13 +23,14 @@ module DnsMock
|
|
22
23
|
@records_dictionary_builder = records_dictionary_builder
|
23
24
|
@thread_class = thread_class
|
24
25
|
@records = records_dictionary_builder.call(records || {})
|
25
|
-
@port = port ||
|
26
|
+
@port = port || 0
|
26
27
|
@exception_if_not_found = exception_if_not_found
|
27
28
|
prepare_server_thread
|
28
29
|
end
|
29
30
|
|
30
31
|
def run
|
31
32
|
prepare_socket_for_session
|
33
|
+
update_server_port
|
32
34
|
|
33
35
|
begin
|
34
36
|
loop do
|
@@ -66,6 +68,7 @@ module DnsMock
|
|
66
68
|
private
|
67
69
|
|
68
70
|
attr_reader :socket, :records_dictionary_builder, :thread_class, :exception_if_not_found
|
71
|
+
attr_writer :port
|
69
72
|
attr_accessor :records, :thread
|
70
73
|
|
71
74
|
def prepare_socket_for_session
|
@@ -76,6 +79,10 @@ module DnsMock
|
|
76
79
|
raise DnsMock::Error::PortInUse.new(DnsMock::Server::CURRENT_HOST_NAME, port)
|
77
80
|
end
|
78
81
|
|
82
|
+
def update_server_port
|
83
|
+
self.port = socket.addr[1] if port.zero?
|
84
|
+
end
|
85
|
+
|
79
86
|
def prepare_server_thread
|
80
87
|
self.thread = thread_class.new { run }
|
81
88
|
thread.join(DnsMock::Server::WARMUP_DELAY)
|
data/lib/dns_mock/version.rb
CHANGED
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: 1.
|
4
|
+
version: 1.3.0
|
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-
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,76 +16,76 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.2.20
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '2.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.2.20
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler-audit
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
39
|
+
version: 0.8.0
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
46
|
+
version: 0.8.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: faker
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 2.15.1
|
53
|
+
version: '2.18'
|
51
54
|
type: :development
|
52
55
|
prerelease: false
|
53
56
|
version_requirements: !ruby/object:Gem::Requirement
|
54
57
|
requirements:
|
55
58
|
- - "~>"
|
56
59
|
- !ruby/object:Gem::Version
|
57
|
-
version: '2.
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 2.15.1
|
60
|
+
version: '2.18'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: fasterer
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.
|
67
|
+
version: 0.9.0
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.
|
74
|
+
version: 0.9.0
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: overcommit
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 0.
|
81
|
+
version: 0.58.0
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 0.
|
88
|
+
version: 0.58.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: pry-byebug
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,7 +129,7 @@ dependencies:
|
|
129
129
|
version: '6.0'
|
130
130
|
- - ">="
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: 6.0.
|
132
|
+
version: 6.0.4
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -139,7 +139,7 @@ dependencies:
|
|
139
139
|
version: '6.0'
|
140
140
|
- - ">="
|
141
141
|
- !ruby/object:Gem::Version
|
142
|
-
version: 6.0.
|
142
|
+
version: 6.0.4
|
143
143
|
- !ruby/object:Gem::Dependency
|
144
144
|
name: rspec
|
145
145
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,48 +174,54 @@ dependencies:
|
|
174
174
|
requirements:
|
175
175
|
- - "~>"
|
176
176
|
- !ruby/object:Gem::Version
|
177
|
-
version: '1.
|
177
|
+
version: '1.16'
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.16.1
|
178
181
|
type: :development
|
179
182
|
prerelease: false
|
180
183
|
version_requirements: !ruby/object:Gem::Requirement
|
181
184
|
requirements:
|
182
185
|
- - "~>"
|
183
186
|
- !ruby/object:Gem::Version
|
184
|
-
version: '1.
|
187
|
+
version: '1.16'
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: 1.16.1
|
185
191
|
- !ruby/object:Gem::Dependency
|
186
192
|
name: rubocop-performance
|
187
193
|
requirement: !ruby/object:Gem::Requirement
|
188
194
|
requirements:
|
189
195
|
- - "~>"
|
190
196
|
- !ruby/object:Gem::Version
|
191
|
-
version: '1.
|
197
|
+
version: '1.11'
|
192
198
|
- - ">="
|
193
199
|
- !ruby/object:Gem::Version
|
194
|
-
version: 1.
|
200
|
+
version: 1.11.3
|
195
201
|
type: :development
|
196
202
|
prerelease: false
|
197
203
|
version_requirements: !ruby/object:Gem::Requirement
|
198
204
|
requirements:
|
199
205
|
- - "~>"
|
200
206
|
- !ruby/object:Gem::Version
|
201
|
-
version: '1.
|
207
|
+
version: '1.11'
|
202
208
|
- - ">="
|
203
209
|
- !ruby/object:Gem::Version
|
204
|
-
version: 1.
|
210
|
+
version: 1.11.3
|
205
211
|
- !ruby/object:Gem::Dependency
|
206
212
|
name: rubocop-rspec
|
207
213
|
requirement: !ruby/object:Gem::Requirement
|
208
214
|
requirements:
|
209
215
|
- - "~>"
|
210
216
|
- !ruby/object:Gem::Version
|
211
|
-
version: '2.
|
217
|
+
version: '2.4'
|
212
218
|
type: :development
|
213
219
|
prerelease: false
|
214
220
|
version_requirements: !ruby/object:Gem::Requirement
|
215
221
|
requirements:
|
216
222
|
- - "~>"
|
217
223
|
- !ruby/object:Gem::Version
|
218
|
-
version: '2.
|
224
|
+
version: '2.4'
|
219
225
|
- !ruby/object:Gem::Dependency
|
220
226
|
name: simplecov
|
221
227
|
requirement: !ruby/object:Gem::Requirement
|
@@ -296,7 +302,6 @@ files:
|
|
296
302
|
- lib/dns_mock/response/answer.rb
|
297
303
|
- lib/dns_mock/response/message.rb
|
298
304
|
- lib/dns_mock/server.rb
|
299
|
-
- lib/dns_mock/server/random_available_port.rb
|
300
305
|
- lib/dns_mock/server/records_dictionary_builder.rb
|
301
306
|
- lib/dns_mock/test_framework/rspec.rb
|
302
307
|
- lib/dns_mock/test_framework/rspec/helper.rb
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DnsMock
|
4
|
-
class Server
|
5
|
-
CURRENT_HOST_NAME = 'localhost'
|
6
|
-
CURRENT_HOST_ADDRESS = '127.0.0.1'
|
7
|
-
|
8
|
-
class RandomAvailablePort
|
9
|
-
ATTEMPTS = 100
|
10
|
-
MIN_DYNAMIC_PORT_NUMBER = 49_152
|
11
|
-
MAX_DYNAMIC_PORT_NUMBER = 65_535
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def call
|
15
|
-
DnsMock::Server::RandomAvailablePort::ATTEMPTS.times do
|
16
|
-
port = rand(
|
17
|
-
DnsMock::Server::RandomAvailablePort::MIN_DYNAMIC_PORT_NUMBER..DnsMock::Server::RandomAvailablePort::MAX_DYNAMIC_PORT_NUMBER
|
18
|
-
)
|
19
|
-
return port if port_free?(port)
|
20
|
-
end
|
21
|
-
raise DnsMock::Error::RandomFreePort, DnsMock::Server::RandomAvailablePort::ATTEMPTS
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def udp_port_free?(port, socket = ::UDPSocket.new)
|
27
|
-
socket.bind(DnsMock::Server::CURRENT_HOST_NAME, port)
|
28
|
-
socket.close
|
29
|
-
true
|
30
|
-
rescue ::Errno::EADDRINUSE
|
31
|
-
false
|
32
|
-
end
|
33
|
-
|
34
|
-
def tcp_port_free?(port, socket = ::Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM, 0))
|
35
|
-
socket.bind(::Socket.sockaddr_in(port, DnsMock::Server::CURRENT_HOST_ADDRESS))
|
36
|
-
socket.close
|
37
|
-
true
|
38
|
-
rescue ::Errno::EADDRINUSE
|
39
|
-
false
|
40
|
-
end
|
41
|
-
|
42
|
-
def port_free?(port)
|
43
|
-
udp_port_free?(port) && tcp_port_free?(port)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|