kong_schema 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +7 -7
- data/lib/kong_schema/reporter.rb +13 -1
- data/lib/kong_schema/resource/api.rb +16 -1
- data/lib/kong_schema/version.rb +1 -1
- metadata +9 -38
- data/.gitignore +0 -3
- data/.rspec +0 -1
- data/.rubocop.yml +0 -31
- data/.ruby-version +0 -1
- data/kong_schema.gemspec +0 -30
- data/spec/examples.txt +0 -0
- data/spec/fixtures/.gitkeep +0 -0
- data/spec/kong_schema/cli_spec.rb +0 -135
- data/spec/kong_schema/client_spec.rb +0 -9
- data/spec/kong_schema/reporter_spec.rb +0 -85
- data/spec/kong_schema/resource/api_spec.rb +0 -121
- data/spec/kong_schema/resource/plugin_spec.rb +0 -126
- data/spec/kong_schema/resource/target_spec.rb +0 -205
- data/spec/kong_schema/resource/upstream_spec.rb +0 -118
- data/spec/spec_helper.rb +0 -115
- data/spec/support/coverage.rb +0 -18
- data/spec/support/kong_schema_test_utils.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07c38fd45ad857c1d106e563a717e1adad472b83
|
4
|
+
data.tar.gz: b000dc659c55e8d550a49ad003d0359592380235
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97da9bea2762e350dc5d8ec6beb65ba340dbcd65caf19fab44baa872542f5ee72e531d63605dec04d08084e8b2a0bd13034e3861006d43ddf24f7f3ae88dc58b
|
7
|
+
data.tar.gz: 0d0c6a0770c4a78d4ab1bb9c7cb3417cb3f3a2afe5183cb327a50670b6c377ca9fb82d3a7359d8ae54337686b1b25137accda471f010755c3c8b2a3a0639a0b9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 1.3.4
|
2
|
+
|
3
|
+
- Fixed an issue that was causing Api objects to appear empty in a diff when in
|
4
|
+
fact there were changed attributes
|
5
|
+
- Fixed another issue in reporting diffs of Api objects where the "methods"
|
6
|
+
property was reported to be changed when in fact, it won't
|
7
|
+
|
1
8
|
## 1.3.3
|
2
9
|
|
3
10
|
- Fixing bad release 1.3.2 ...
|
data/Gemfile.lock
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kong_schema (1.3.
|
5
|
-
diffy (~> 3.
|
4
|
+
kong_schema (1.3.4)
|
5
|
+
diffy (~> 3.2)
|
6
6
|
gli (~> 2.16)
|
7
7
|
json (~> 2.1)
|
8
8
|
kong (~> 0.3)
|
9
|
-
tty-prompt (~> 0.
|
10
|
-
tty-table (~> 0.
|
9
|
+
tty-prompt (~> 0.16)
|
10
|
+
tty-table (~> 0.10)
|
11
11
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
15
|
diff-lcs (1.3)
|
16
|
-
diffy (3.2.
|
16
|
+
diffy (3.2.1)
|
17
17
|
docile (1.1.5)
|
18
18
|
equatable (0.5.0)
|
19
19
|
excon (0.62.0)
|
20
20
|
gli (2.17.1)
|
21
|
-
hitimes (1.
|
21
|
+
hitimes (1.3.0)
|
22
22
|
json (2.1.0)
|
23
23
|
kong (0.3.2)
|
24
24
|
excon
|
@@ -69,7 +69,7 @@ GEM
|
|
69
69
|
pastel (~> 0.7.2)
|
70
70
|
strings (~> 0.1.0)
|
71
71
|
tty-screen (~> 0.6.4)
|
72
|
-
unicode-display_width (1.3.
|
72
|
+
unicode-display_width (1.3.3)
|
73
73
|
unicode_utils (1.4.0)
|
74
74
|
wisper (2.0.0)
|
75
75
|
|
data/lib/kong_schema/reporter.rb
CHANGED
@@ -64,8 +64,9 @@ module KongSchema
|
|
64
64
|
map
|
65
65
|
end
|
66
66
|
|
67
|
-
changed_attributes = pretty_print.call(change.params)
|
67
|
+
changed_attributes = pretty_print.call(normalize_api_attributes(change.record, change.params))
|
68
68
|
current_attributes = pretty_print.call(current_attributes)
|
69
|
+
|
69
70
|
diff = Diffy::Diff.new(current_attributes, changed_attributes)
|
70
71
|
|
71
72
|
[ "Update #{resource_name}", diff.to_s(:color) ]
|
@@ -77,6 +78,15 @@ module KongSchema
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
81
|
+
def normalize_api_attributes(record, attrs)
|
82
|
+
case record
|
83
|
+
when Kong::Api
|
84
|
+
attrs.merge('methods' => attrs['methods'].split(','))
|
85
|
+
else
|
86
|
+
attrs
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
80
90
|
# This warrants some explanation.
|
81
91
|
#
|
82
92
|
# For some Kong API objects like Target, the API will accept "indirect"
|
@@ -91,6 +101,8 @@ module KongSchema
|
|
91
101
|
# meant to input (e.g. target.upstream_id -> target.upstream.name)
|
92
102
|
def rewrite_record_attributes(record)
|
93
103
|
case record
|
104
|
+
when Kong::Api
|
105
|
+
record.attributes
|
94
106
|
when Kong::Target
|
95
107
|
record.attributes.merge('upstream_id' => record.upstream.name)
|
96
108
|
else
|
@@ -45,7 +45,22 @@ module KongSchema
|
|
45
45
|
map
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
normal_attributes = attributes.keys.reduce({}) do |map, key|
|
49
|
+
value = attributes[key]
|
50
|
+
|
51
|
+
case key
|
52
|
+
# sometimes the API reports it an array, sometimes a string, sometimes
|
53
|
+
# nil...
|
54
|
+
when 'methods'
|
55
|
+
map[key] = Array(value).join(',').split(',')
|
56
|
+
else
|
57
|
+
map[key] = value
|
58
|
+
end
|
59
|
+
|
60
|
+
map
|
61
|
+
end
|
62
|
+
|
63
|
+
Adapter.for(Kong::Api).changed?(current, normal_attributes)
|
49
64
|
end
|
50
65
|
|
51
66
|
def update(record, partial_attributes)
|
data/lib/kong_schema/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kong_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmad Amireh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.2'
|
34
34
|
type: :runtime
|
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: '3.
|
40
|
+
version: '3.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,28 +72,28 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.16'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.16'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: tty-table
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.10'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.10'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: bundler
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,10 +158,6 @@ executables:
|
|
158
158
|
extensions: []
|
159
159
|
extra_rdoc_files: []
|
160
160
|
files:
|
161
|
-
- ".gitignore"
|
162
|
-
- ".rspec"
|
163
|
-
- ".rubocop.yml"
|
164
|
-
- ".ruby-version"
|
165
161
|
- CHANGELOG.md
|
166
162
|
- Gemfile
|
167
163
|
- Gemfile.lock
|
@@ -169,7 +165,6 @@ files:
|
|
169
165
|
- README.md
|
170
166
|
- bin/kong_schema
|
171
167
|
- ext/kong/upstream.rb
|
172
|
-
- kong_schema.gemspec
|
173
168
|
- lib/kong_schema.rb
|
174
169
|
- lib/kong_schema/actions.rb
|
175
170
|
- lib/kong_schema/adapter.rb
|
@@ -184,18 +179,6 @@ files:
|
|
184
179
|
- lib/kong_schema/resource/upstream.rb
|
185
180
|
- lib/kong_schema/schema.rb
|
186
181
|
- lib/kong_schema/version.rb
|
187
|
-
- spec/examples.txt
|
188
|
-
- spec/fixtures/.gitkeep
|
189
|
-
- spec/kong_schema/cli_spec.rb
|
190
|
-
- spec/kong_schema/client_spec.rb
|
191
|
-
- spec/kong_schema/reporter_spec.rb
|
192
|
-
- spec/kong_schema/resource/api_spec.rb
|
193
|
-
- spec/kong_schema/resource/plugin_spec.rb
|
194
|
-
- spec/kong_schema/resource/target_spec.rb
|
195
|
-
- spec/kong_schema/resource/upstream_spec.rb
|
196
|
-
- spec/spec_helper.rb
|
197
|
-
- spec/support/coverage.rb
|
198
|
-
- spec/support/kong_schema_test_utils.rb
|
199
182
|
homepage: https://github.com/amireh/kong_schema
|
200
183
|
licenses:
|
201
184
|
- AGPL-3.0
|
@@ -220,17 +203,5 @@ rubygems_version: 2.5.2
|
|
220
203
|
signing_key:
|
221
204
|
specification_version: 4
|
222
205
|
summary: Configure Kong from a file using its REST API.
|
223
|
-
test_files:
|
224
|
-
- spec/examples.txt
|
225
|
-
- spec/fixtures/.gitkeep
|
226
|
-
- spec/kong_schema/cli_spec.rb
|
227
|
-
- spec/kong_schema/client_spec.rb
|
228
|
-
- spec/kong_schema/reporter_spec.rb
|
229
|
-
- spec/kong_schema/resource/api_spec.rb
|
230
|
-
- spec/kong_schema/resource/plugin_spec.rb
|
231
|
-
- spec/kong_schema/resource/target_spec.rb
|
232
|
-
- spec/kong_schema/resource/upstream_spec.rb
|
233
|
-
- spec/spec_helper.rb
|
234
|
-
- spec/support/coverage.rb
|
235
|
-
- spec/support/kong_schema_test_utils.rb
|
206
|
+
test_files: []
|
236
207
|
has_rdoc:
|
data/.gitignore
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--require spec_helper
|
data/.rubocop.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
Exclude:
|
3
|
-
- 'spec/**/*_spec.rb'
|
4
|
-
- 'lib/kong_schema/cli.rb'
|
5
|
-
|
6
|
-
Lint/EndAlignment:
|
7
|
-
AlignWith: variable
|
8
|
-
|
9
|
-
Style/EachWithObject:
|
10
|
-
Enabled: false
|
11
|
-
|
12
|
-
Style/SpaceInsideBrackets:
|
13
|
-
Enabled: false
|
14
|
-
|
15
|
-
Style/Documentation:
|
16
|
-
Enabled: false
|
17
|
-
|
18
|
-
Style/StringLiterals:
|
19
|
-
Enabled: false
|
20
|
-
|
21
|
-
Style/FrozenStringLiteralComment:
|
22
|
-
Enabled: false
|
23
|
-
|
24
|
-
Style/SignalException:
|
25
|
-
Enabled: false
|
26
|
-
|
27
|
-
Metrics/MethodLength:
|
28
|
-
Max: 25
|
29
|
-
|
30
|
-
Style/ModuleFunction:
|
31
|
-
EnforcedStyle: extend_self
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.3.4
|
data/kong_schema.gemspec
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require_relative "./lib/kong_schema/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "kong_schema"
|
7
|
-
spec.version = KongSchema::VERSION
|
8
|
-
spec.authors = ["Ahmad Amireh"]
|
9
|
-
spec.email = ["ahmad@instructure.com"]
|
10
|
-
spec.summary = "Configure Kong from a file using its REST API."
|
11
|
-
spec.license = 'AGPL-3.0'
|
12
|
-
spec.homepage = 'https://github.com/amireh/kong_schema'
|
13
|
-
|
14
|
-
spec.files = `git ls-files -z`.split("\x0")
|
15
|
-
spec.executables = %w(kong_schema)
|
16
|
-
spec.test_files = spec.files.grep(%r{^spec/})
|
17
|
-
spec.require_paths = %w(lib)
|
18
|
-
|
19
|
-
spec.add_dependency "gli", "~> 2.16"
|
20
|
-
spec.add_dependency "diffy", "~> 3.1"
|
21
|
-
spec.add_dependency "json", "~> 2.1"
|
22
|
-
spec.add_dependency "kong", "~> 0.3"
|
23
|
-
spec.add_dependency "tty-prompt", "~> 0.13"
|
24
|
-
spec.add_dependency "tty-table", "~> 0.8"
|
25
|
-
|
26
|
-
spec.add_development_dependency "bundler", "~> 1.15"
|
27
|
-
spec.add_development_dependency "rspec", "~> 3.6"
|
28
|
-
spec.add_development_dependency "simplecov", "~> 0.15"
|
29
|
-
spec.add_development_dependency "simplecov_compact_json", "~> 1.0"
|
30
|
-
end
|
data/spec/examples.txt
DELETED
File without changes
|
data/spec/fixtures/.gitkeep
DELETED
File without changes
|
@@ -1,135 +0,0 @@
|
|
1
|
-
describe KongSchema::CLI do
|
2
|
-
let(:test_utils) { KongSchemaTestUtils.new }
|
3
|
-
let(:schema) { KongSchema::Schema }
|
4
|
-
let(:client) { KongSchema::Client }
|
5
|
-
|
6
|
-
let(:config) do
|
7
|
-
test_utils.generate_config({
|
8
|
-
apis: [{
|
9
|
-
name: 'my-api',
|
10
|
-
hosts: [ 'example.com' ],
|
11
|
-
upstream_url: 'http://example'
|
12
|
-
}]
|
13
|
-
})
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:keyed_config) do
|
17
|
-
{
|
18
|
-
"kong" => config
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'up' do
|
23
|
-
it 'complains if no file was passed' do
|
24
|
-
expect(subject).to receive(:bail!)
|
25
|
-
.with('Missing path to .yml or .json config file')
|
26
|
-
.and_call_original
|
27
|
-
|
28
|
-
expect {
|
29
|
-
subject.run(["up"])
|
30
|
-
}.to output(/Missing path to/).to_stderr_from_any_process
|
31
|
-
.and output(/SYNOPSIS/).to_stdout_from_any_process # help listing
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'works' do
|
35
|
-
test_utils.generate_config_file(config) do |filepath|
|
36
|
-
expect {
|
37
|
-
subject.run(["up", filepath, "--no-confirm", "--key", ""])
|
38
|
-
}.to change { client.connect(config) { Kong::Api.all.count } }.by(1)
|
39
|
-
.and output(/Kong has been reconfigured!/).to_stdout
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'works (with a JSON file)' do
|
44
|
-
test_utils.generate_config_file(config, format: :json) do |filepath|
|
45
|
-
expect {
|
46
|
-
subject.run(["up", filepath, "--no-confirm", "--key", ""])
|
47
|
-
}.to change { client.connect(config) { Kong::Api.all.count } }.by(1)
|
48
|
-
.and output(/Kong has been reconfigured!/).to_stdout
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'accepts config file using -c for consistency with Kong' do
|
53
|
-
test_utils.generate_config_file(keyed_config) do |filepath|
|
54
|
-
expect {
|
55
|
-
subject.run(["up", "-c", filepath, "--no-confirm"])
|
56
|
-
}.to change { client.connect(config) { Kong::Api.all.count } }.by(1)
|
57
|
-
.and output(/Kong has been reconfigured!/).to_stdout
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'accepts config file using -c (globally) for convenience' do
|
62
|
-
test_utils.generate_config_file(keyed_config) do |filepath|
|
63
|
-
expect {
|
64
|
-
subject.run(["-c", filepath, "up", "--no-confirm"])
|
65
|
-
}.to change { client.connect(config) { Kong::Api.all.count } }.by(1)
|
66
|
-
.and output(/Kong has been reconfigured!/).to_stdout
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'reads config from a custom key' do
|
71
|
-
test_utils.generate_config_file(keyed_config) do |filepath|
|
72
|
-
expect {
|
73
|
-
subject.run(["up", filepath, "--no-confirm", "--key", "kong"])
|
74
|
-
}.to change { client.connect(config) { Kong::Api.all.count } }.by(1)
|
75
|
-
.and output(/Kong has been reconfigured!/).to_stdout
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'prompts for confirmation' do
|
80
|
-
test_utils.fake_stdin(["y"]) do
|
81
|
-
test_utils.generate_config_file(keyed_config) do |filepath|
|
82
|
-
expect {
|
83
|
-
subject.run(["up", filepath])
|
84
|
-
}.to change { client.connect(config) { Kong::Api.all.count } }.by(1)
|
85
|
-
.and output(/Kong has been reconfigured!/).to_stdout
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'aborts if not confirmed' do
|
91
|
-
test_utils.fake_stdin(["n"]) do
|
92
|
-
test_utils.generate_config_file(keyed_config) do |filepath|
|
93
|
-
expect {
|
94
|
-
subject.run(["up", filepath])
|
95
|
-
}.to change { client.connect(config) { Kong::Api.all.count } }.by(0)
|
96
|
-
.and output.to_stdout
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'does nothing if there are no changes to commit' do
|
102
|
-
config = test_utils.generate_config({})
|
103
|
-
|
104
|
-
test_utils.generate_config_file(config) do |filepath|
|
105
|
-
expect {
|
106
|
-
subject.run(["up", filepath, "--no-confirm", "--key", ""])
|
107
|
-
}.to output(/Nothing to update./).to_stdout
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe 'down' do
|
113
|
-
it 'complains if no file was passed' do
|
114
|
-
expect(subject).to receive(:bail!)
|
115
|
-
.with('Missing path to .yml or .json config file')
|
116
|
-
.and_call_original
|
117
|
-
|
118
|
-
expect {
|
119
|
-
subject.run(["down"])
|
120
|
-
}.to output(/Missing path to/).to_stderr_from_any_process
|
121
|
-
.and output(/SYNOPSIS/).to_stdout_from_any_process # help listing
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'works' do
|
125
|
-
KongSchema::Schema.commit(config, KongSchema::Schema.scan(config))
|
126
|
-
|
127
|
-
test_utils.generate_config_file(config) do |filepath|
|
128
|
-
expect {
|
129
|
-
subject.run(["down", filepath, "--no-confirm", "--key", ""])
|
130
|
-
}.to change { client.connect(config) { Kong::Api.all.count } }.by(-1)
|
131
|
-
.and output(/Kong reset\./).to_stdout
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
describe KongSchema::Reporter do
|
2
|
-
subject { described_class }
|
3
|
-
|
4
|
-
let(:test_utils) { KongSchemaTestUtils.new }
|
5
|
-
let(:schema) { KongSchema::Schema }
|
6
|
-
|
7
|
-
let :config do
|
8
|
-
test_utils.generate_config({
|
9
|
-
upstreams: [{ name: 'bridge-learn.kong-service' }]
|
10
|
-
})
|
11
|
-
end
|
12
|
-
|
13
|
-
let :with_updated_config do
|
14
|
-
test_utils.generate_config({
|
15
|
-
upstreams: [{
|
16
|
-
name: 'bridge-learn.kong-service',
|
17
|
-
slots: 50,
|
18
|
-
orderlist: nil
|
19
|
-
}]
|
20
|
-
})
|
21
|
-
end
|
22
|
-
|
23
|
-
let :with_deleted_config do
|
24
|
-
test_utils.generate_config({
|
25
|
-
upstreams: []
|
26
|
-
})
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'reports a resource to be created' do
|
30
|
-
report = subject.report(schema.scan(config))
|
31
|
-
|
32
|
-
expect(report).to include('Create Upstream')
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'reports a resource to be updated [JSON]' do
|
36
|
-
schema.commit(config, schema.scan(config))
|
37
|
-
|
38
|
-
report = subject.report(schema.scan(with_updated_config))
|
39
|
-
|
40
|
-
expect(report).to include('Update Upstream')
|
41
|
-
expect(report).to match(/\-[ ]*"slots": 100/)
|
42
|
-
expect(report).to match(/\+[ ]*"slots": 50/)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'reports a resource to be updated [YAML]' do
|
46
|
-
schema.commit(config, schema.scan(config))
|
47
|
-
|
48
|
-
report = subject.report(schema.scan(with_updated_config), object_format: :yaml)
|
49
|
-
|
50
|
-
expect(report).to include('Update Upstream')
|
51
|
-
expect(report).to include('-slots: 100')
|
52
|
-
expect(report).to include('+slots: 50')
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'reports a resource to be deleted' do
|
56
|
-
schema.commit(config, schema.scan(config))
|
57
|
-
|
58
|
-
report = subject.report(schema.scan(with_deleted_config))
|
59
|
-
|
60
|
-
expect(report).to include('Delete Upstream')
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '.extract_record_attributes' do
|
64
|
-
context 'Kong::Target' do
|
65
|
-
it 'it rewrites "upstream_id" into the upstream name' do
|
66
|
-
with_target = test_utils.generate_config({
|
67
|
-
upstreams: [{ name: 'foo' }],
|
68
|
-
targets: [{ upstream_id: 'foo', target: '127.0.0.1' }]
|
69
|
-
})
|
70
|
-
|
71
|
-
with_updated_target = test_utils.generate_config({
|
72
|
-
upstreams: [{ name: 'foo' }],
|
73
|
-
targets: []
|
74
|
-
})
|
75
|
-
|
76
|
-
schema.commit(with_target, schema.scan(with_target))
|
77
|
-
|
78
|
-
next_changes = schema.scan(with_updated_target)
|
79
|
-
report = subject.report(next_changes, object_format: :yml)
|
80
|
-
|
81
|
-
expect(report).to include('upstream_id: foo')
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
describe KongSchema::Resource::Api do
|
2
|
-
let(:schema) { KongSchema::Schema }
|
3
|
-
let(:test_utils) { KongSchemaTestUtils.new }
|
4
|
-
|
5
|
-
describe 'creating APIs' do
|
6
|
-
let :config do
|
7
|
-
test_utils.generate_config({
|
8
|
-
apis: [{
|
9
|
-
name: 'bridge-learn',
|
10
|
-
hosts: ['bridgeapp.com'],
|
11
|
-
upstream_url: 'http://bridge-learn.kong-service'
|
12
|
-
}]
|
13
|
-
})
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'adds an API if it does not exist' do
|
17
|
-
directives = schema.scan(config)
|
18
|
-
|
19
|
-
expect(directives.map(&:class)).to include(KongSchema::Actions::Create)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'does add an API' do
|
23
|
-
directives = schema.scan(config)
|
24
|
-
|
25
|
-
expect {
|
26
|
-
schema.commit(config, directives)
|
27
|
-
}.to change {
|
28
|
-
KongSchema::Client.connect(config) { Kong::Api.all.count }
|
29
|
-
}.by(1)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'does not add an API if it exists' do
|
33
|
-
directives = schema.scan(config)
|
34
|
-
|
35
|
-
schema.commit(config, directives)
|
36
|
-
|
37
|
-
next_directives = schema.scan(config)
|
38
|
-
|
39
|
-
expect(next_directives.map(&:class)).not_to include(KongSchema::Actions::Create)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'updating APIs' do
|
44
|
-
let :config do
|
45
|
-
test_utils.generate_config({
|
46
|
-
apis: [{
|
47
|
-
name: 'bridge-learn',
|
48
|
-
hosts: ['bridgeapp.com'],
|
49
|
-
upstream_url: 'http://bridge-learn.kong-service'
|
50
|
-
}]
|
51
|
-
})
|
52
|
-
end
|
53
|
-
|
54
|
-
let :with_updated_config do
|
55
|
-
test_utils.generate_config({
|
56
|
-
apis: [{
|
57
|
-
name: 'bridge-learn',
|
58
|
-
hosts: ['bar.com'],
|
59
|
-
upstream_url: 'http://bridge-learn.kong-service'
|
60
|
-
}]
|
61
|
-
})
|
62
|
-
end
|
63
|
-
|
64
|
-
before(:each) do
|
65
|
-
schema.commit(config, schema.scan(config))
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'updates an API' do
|
69
|
-
directives = schema.scan(with_updated_config)
|
70
|
-
expect(directives.map(&:class)).to include(KongSchema::Actions::Update)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'does update an API' do
|
74
|
-
directives = schema.scan(with_updated_config)
|
75
|
-
|
76
|
-
expect {
|
77
|
-
schema.commit(with_updated_config, directives)
|
78
|
-
}.to change {
|
79
|
-
KongSchema::Client.connect(config) { Kong::Api.all[0].hosts[0] }
|
80
|
-
}.from('bridgeapp.com').to('bar.com')
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'deleting APIs' do
|
85
|
-
let :config do
|
86
|
-
test_utils.generate_config({
|
87
|
-
apis: [{
|
88
|
-
name: 'bridge-learn',
|
89
|
-
hosts: ['bar.com'],
|
90
|
-
upstream_url: 'http://bridge-learn.kong-service'
|
91
|
-
}]
|
92
|
-
})
|
93
|
-
end
|
94
|
-
|
95
|
-
let :with_deleted_config do
|
96
|
-
test_utils.generate_config({
|
97
|
-
apis: []
|
98
|
-
})
|
99
|
-
end
|
100
|
-
|
101
|
-
before(:each) do
|
102
|
-
schema.commit(config, schema.scan(config))
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'deletes an API' do
|
106
|
-
directives = schema.scan(with_deleted_config)
|
107
|
-
|
108
|
-
expect(directives.map(&:class)).to include(KongSchema::Actions::Delete)
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'does delete an API' do
|
112
|
-
directives = schema.scan(with_deleted_config)
|
113
|
-
|
114
|
-
expect {
|
115
|
-
schema.commit(with_deleted_config, directives)
|
116
|
-
}.to change {
|
117
|
-
KongSchema::Client.connect(config) { Kong::Api.all.count }
|
118
|
-
}.from(1).to(0)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
describe KongSchema::Resource::Plugin do
|
2
|
-
let(:schema) { KongSchema::Schema }
|
3
|
-
let(:test_utils) { KongSchemaTestUtils.new }
|
4
|
-
|
5
|
-
let :plugin_config do
|
6
|
-
{
|
7
|
-
second: 120
|
8
|
-
}
|
9
|
-
end
|
10
|
-
|
11
|
-
let :config do
|
12
|
-
test_utils.generate_config({
|
13
|
-
plugins: [{
|
14
|
-
name: 'rate-limiting',
|
15
|
-
enabled: true,
|
16
|
-
config: plugin_config
|
17
|
-
}]
|
18
|
-
})
|
19
|
-
end
|
20
|
-
|
21
|
-
let :config_with_custom_options do
|
22
|
-
test_utils.generate_config({
|
23
|
-
plugins: [{
|
24
|
-
name: 'rate-limiting',
|
25
|
-
enabled: true,
|
26
|
-
config: plugin_config.merge({ second: 60 }),
|
27
|
-
}]
|
28
|
-
})
|
29
|
-
end
|
30
|
-
|
31
|
-
let :config_with_api do
|
32
|
-
test_utils.generate_config({
|
33
|
-
apis: [{
|
34
|
-
name: 'my-api',
|
35
|
-
upstream_url: 'http://example.com',
|
36
|
-
hosts: [ 'example.com' ]
|
37
|
-
}],
|
38
|
-
|
39
|
-
plugins: [{
|
40
|
-
name: 'rate-limiting',
|
41
|
-
api_id: 'my-api',
|
42
|
-
enabled: true,
|
43
|
-
config: plugin_config
|
44
|
-
}]
|
45
|
-
})
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'identifies plugins to be added' do
|
49
|
-
directives = schema.scan(config)
|
50
|
-
|
51
|
-
expect(directives.map(&:class)).to eq([ KongSchema::Actions::Create ])
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'adds a plugin' do
|
55
|
-
directives = schema.scan(config)
|
56
|
-
|
57
|
-
expect {
|
58
|
-
schema.commit(config, directives)
|
59
|
-
}.to change {
|
60
|
-
KongSchema::Client.connect(config) {
|
61
|
-
Kong::Plugin.all.count
|
62
|
-
}
|
63
|
-
}.by(1)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'adds a plugin with an api' do
|
67
|
-
directives = schema.scan(config_with_api)
|
68
|
-
|
69
|
-
expect {
|
70
|
-
schema.commit(config_with_api, directives)
|
71
|
-
}.to change {
|
72
|
-
KongSchema::Client.connect(config_with_api) {
|
73
|
-
Kong::Plugin.all.count
|
74
|
-
}
|
75
|
-
}.by(1)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'identifies plugins to be updated' do
|
79
|
-
schema.commit(config, schema.scan(config))
|
80
|
-
changes = schema.scan(config_with_custom_options)
|
81
|
-
|
82
|
-
expect(changes.map(&:class)).to eq([ KongSchema::Actions::Update ])
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'updates a plugin' do
|
86
|
-
schema.commit(config, schema.scan(config))
|
87
|
-
|
88
|
-
expect { schema.commit(config, schema.scan(config_with_custom_options)) }.to change {
|
89
|
-
KongSchema::Client.connect(config) {
|
90
|
-
Kong::Plugin.find_by_name('rate-limiting').config['second']
|
91
|
-
}
|
92
|
-
}.from(120).to(60)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'removes the plugin if enabled is set to false' do
|
96
|
-
schema.commit(config, schema.scan(config))
|
97
|
-
|
98
|
-
with_update = test_utils.generate_config({
|
99
|
-
plugins: [{
|
100
|
-
name: 'rate-limiting',
|
101
|
-
config: plugin_config,
|
102
|
-
enabled: false
|
103
|
-
}]
|
104
|
-
})
|
105
|
-
|
106
|
-
expect { schema.commit(config, schema.scan(with_update)) }.to change {
|
107
|
-
KongSchema::Client.connect(config) {
|
108
|
-
Kong::Plugin.all.count
|
109
|
-
}
|
110
|
-
}.by(-1)
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'removes the plugin if it is no longer specified' do
|
114
|
-
schema.commit(config, schema.scan(config))
|
115
|
-
|
116
|
-
with_removal = test_utils.generate_config({
|
117
|
-
plugins: []
|
118
|
-
})
|
119
|
-
|
120
|
-
expect { schema.commit(config, schema.scan(with_removal)) }.to change {
|
121
|
-
KongSchema::Client.connect(config) {
|
122
|
-
Kong::Plugin.all.count
|
123
|
-
}
|
124
|
-
}.by(-1)
|
125
|
-
end
|
126
|
-
end
|
@@ -1,205 +0,0 @@
|
|
1
|
-
describe KongSchema::Resource::Target do
|
2
|
-
let(:schema) { KongSchema::Schema }
|
3
|
-
let(:test_utils) { KongSchemaTestUtils.new }
|
4
|
-
|
5
|
-
describe 'creating targets' do
|
6
|
-
let :config do
|
7
|
-
test_utils.generate_config({
|
8
|
-
upstreams: [{
|
9
|
-
name: 'bridge-learn.kong-service'
|
10
|
-
}],
|
11
|
-
|
12
|
-
targets: [{
|
13
|
-
upstream_id: 'bridge-learn.kong-service',
|
14
|
-
target: '127.0.0.1:3000'
|
15
|
-
}]
|
16
|
-
})
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'adds a target if it does not exist' do
|
20
|
-
directives = schema.scan(config)
|
21
|
-
|
22
|
-
expect(directives.map(&:class)).to eq([ KongSchema::Actions::Create, KongSchema::Actions::Create ])
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'does add a target' do
|
26
|
-
directives = schema.scan(config)
|
27
|
-
|
28
|
-
expect {
|
29
|
-
schema.commit(config, directives)
|
30
|
-
}.to change {
|
31
|
-
KongSchema::Client.connect(config) { Kong::Upstream.all.count }
|
32
|
-
}.by(1)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'does not add a target if it exists' do
|
36
|
-
directives = schema.scan(config)
|
37
|
-
|
38
|
-
schema.commit(config, directives)
|
39
|
-
|
40
|
-
next_directives = schema.scan(config)
|
41
|
-
|
42
|
-
expect(next_directives.map(&:class)).not_to include(KongSchema::Actions::Create)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'does not allow defining a target without an upstream_id' do
|
46
|
-
directives = schema.scan(test_utils.generate_config({
|
47
|
-
targets: [{ target: '127.0.0.1:3000' }]
|
48
|
-
}))
|
49
|
-
|
50
|
-
expect {
|
51
|
-
schema.commit(config, directives)
|
52
|
-
}.to raise_error(/Can not add a target without an upstream!/)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "changing a target's target" do
|
57
|
-
let :config do
|
58
|
-
test_utils.generate_config({
|
59
|
-
upstreams: [{
|
60
|
-
name: 'bridge-learn.kong-service'
|
61
|
-
}],
|
62
|
-
|
63
|
-
targets: [{
|
64
|
-
upstream_id: 'bridge-learn.kong-service',
|
65
|
-
target: '127.0.0.1:3000'
|
66
|
-
}]
|
67
|
-
})
|
68
|
-
end
|
69
|
-
|
70
|
-
let :with_updated do
|
71
|
-
test_utils.generate_config({
|
72
|
-
upstreams: [{
|
73
|
-
name: 'bridge-learn.kong-service'
|
74
|
-
}],
|
75
|
-
|
76
|
-
targets: [{
|
77
|
-
upstream_id: 'bridge-learn.kong-service',
|
78
|
-
target: '127.0.0.1:9999'
|
79
|
-
}]
|
80
|
-
})
|
81
|
-
end
|
82
|
-
|
83
|
-
before(:each) do
|
84
|
-
schema.commit(config, schema.scan(config))
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'identifies targets to be updated' do
|
88
|
-
directives = schema.scan(with_updated)
|
89
|
-
|
90
|
-
expect(directives.map(&:class)).to eq([KongSchema::Actions::Create, KongSchema::Actions::Delete])
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'updates a target' do
|
94
|
-
expect {
|
95
|
-
schema.commit(with_updated, schema.scan(with_updated))
|
96
|
-
}.to change {
|
97
|
-
KongSchema::Client.connect(config) {
|
98
|
-
KongSchema::Resource::Target.all.map { |x| [ x.weight, x.target ] }
|
99
|
-
}
|
100
|
-
}.from([
|
101
|
-
[ 100, '127.0.0.1:3000' ]
|
102
|
-
]).to([
|
103
|
-
[ 100, '127.0.0.1:9999' ]
|
104
|
-
])
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "changing a target's weight" do
|
109
|
-
let :config do
|
110
|
-
test_utils.generate_config({
|
111
|
-
upstreams: [{
|
112
|
-
name: 'bridge-learn.kong-service'
|
113
|
-
}],
|
114
|
-
|
115
|
-
targets: [{
|
116
|
-
upstream_id: 'bridge-learn.kong-service',
|
117
|
-
target: '127.0.0.1:3000'
|
118
|
-
}]
|
119
|
-
})
|
120
|
-
end
|
121
|
-
|
122
|
-
let :with_different_weight do
|
123
|
-
test_utils.generate_config({
|
124
|
-
upstreams: [{
|
125
|
-
name: 'bridge-learn.kong-service'
|
126
|
-
}],
|
127
|
-
|
128
|
-
targets: [{
|
129
|
-
upstream_id: 'bridge-learn.kong-service',
|
130
|
-
target: '127.0.0.1:3000',
|
131
|
-
weight: 20
|
132
|
-
}]
|
133
|
-
})
|
134
|
-
end
|
135
|
-
|
136
|
-
before(:each) do
|
137
|
-
schema.commit(config, schema.scan(config))
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'updates the existing target' do
|
141
|
-
directives = schema.scan(with_different_weight)
|
142
|
-
|
143
|
-
expect(directives.map(&:class)).to eq([ KongSchema::Actions::Update ])
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'updates a target' do
|
147
|
-
expect {
|
148
|
-
schema.commit(with_different_weight, schema.scan(with_different_weight))
|
149
|
-
}.to change {
|
150
|
-
KongSchema::Client.connect(config) {
|
151
|
-
KongSchema::Resource::Target.all.map { |x| [ x.weight, x.target ] }
|
152
|
-
}
|
153
|
-
}.from([
|
154
|
-
[ 100, '127.0.0.1:3000' ]
|
155
|
-
]).to([
|
156
|
-
[ 20, '127.0.0.1:3000' ]
|
157
|
-
])
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe 'deleting targets' do
|
162
|
-
let :config do
|
163
|
-
test_utils.generate_config(
|
164
|
-
upstreams: [{
|
165
|
-
name: 'bridge-learn.kong-service'
|
166
|
-
}],
|
167
|
-
|
168
|
-
targets: [{
|
169
|
-
upstream_id: 'bridge-learn.kong-service',
|
170
|
-
target: '127.0.0.1:3000'
|
171
|
-
}]
|
172
|
-
)
|
173
|
-
end
|
174
|
-
|
175
|
-
let :with_deleted do
|
176
|
-
test_utils.generate_config(
|
177
|
-
upstreams: [{ name: 'bridge-learn.kong-service' }],
|
178
|
-
targets: []
|
179
|
-
)
|
180
|
-
end
|
181
|
-
|
182
|
-
before(:each) do
|
183
|
-
schema.commit(config, schema.scan(config))
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'identifies targets to be deleted' do
|
187
|
-
directives = schema.scan(with_deleted)
|
188
|
-
|
189
|
-
expect(directives.map(&:class)).to include(KongSchema::Actions::Delete)
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'deletes a target' do
|
193
|
-
expect {
|
194
|
-
schema.commit(with_deleted, schema.scan(with_deleted))
|
195
|
-
}.to change {
|
196
|
-
KongSchema::Client.connect(config) {
|
197
|
-
KongSchema::Resource::Target.all.map { |x| [ x.target, x.weight ] }
|
198
|
-
}
|
199
|
-
}.from([
|
200
|
-
[ '127.0.0.1:3000', 100 ]
|
201
|
-
]).to([
|
202
|
-
])
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
describe KongSchema::Resource::Upstream do
|
2
|
-
let(:schema) { KongSchema::Schema }
|
3
|
-
let(:test_utils) { KongSchemaTestUtils.new }
|
4
|
-
|
5
|
-
describe 'creating upstreams' do
|
6
|
-
let :config do
|
7
|
-
test_utils.generate_config({
|
8
|
-
upstreams: [{
|
9
|
-
name: 'bridge-learn.kong-service'
|
10
|
-
}]
|
11
|
-
})
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'adds an upstream if it does not exist' do
|
15
|
-
changes = schema.scan(config)
|
16
|
-
|
17
|
-
expect(changes.map(&:class)).to include(KongSchema::Actions::Create)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'does add an upstream' do
|
21
|
-
changes = schema.scan(config)
|
22
|
-
|
23
|
-
expect {
|
24
|
-
schema.commit(config, changes)
|
25
|
-
}.to change {
|
26
|
-
KongSchema::Client.connect(config) { Kong::Upstream.all.count }
|
27
|
-
}.by(1)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'does not add an upstream if it exists' do
|
31
|
-
changes = schema.scan(config)
|
32
|
-
|
33
|
-
schema.commit(config, changes)
|
34
|
-
|
35
|
-
next_changes = schema.scan(config)
|
36
|
-
|
37
|
-
expect(next_changes.map(&:class)).not_to include(KongSchema::Actions::Create)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'updating upstreams' do
|
42
|
-
let :config do
|
43
|
-
test_utils.generate_config({
|
44
|
-
upstreams: [{
|
45
|
-
name: 'bridge-learn.kong-service',
|
46
|
-
}]
|
47
|
-
})
|
48
|
-
end
|
49
|
-
|
50
|
-
let :with_updated_config do
|
51
|
-
test_utils.generate_config({
|
52
|
-
upstreams: [{
|
53
|
-
name: 'bridge-learn.kong-service',
|
54
|
-
slots: 50,
|
55
|
-
orderlist: nil
|
56
|
-
}]
|
57
|
-
})
|
58
|
-
end
|
59
|
-
|
60
|
-
before(:each) do
|
61
|
-
schema.commit(config, schema.scan(config))
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'updates an upstream' do
|
65
|
-
changes = schema.scan(with_updated_config)
|
66
|
-
|
67
|
-
expect(changes.map(&:class)).to eq([ KongSchema::Actions::Update ])
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'does update an upstream' do
|
71
|
-
changes = schema.scan(with_updated_config)
|
72
|
-
|
73
|
-
expect {
|
74
|
-
schema.commit(with_updated_config, changes)
|
75
|
-
}.to change {
|
76
|
-
KongSchema::Client.connect(config) {
|
77
|
-
Kong::Upstream.all.first.slots
|
78
|
-
}
|
79
|
-
}.from(100).to(50)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe 'deleting upstreams' do
|
84
|
-
let :config do
|
85
|
-
test_utils.generate_config({
|
86
|
-
upstreams: [{
|
87
|
-
name: 'bridge-learn.kong-service',
|
88
|
-
}]
|
89
|
-
})
|
90
|
-
end
|
91
|
-
|
92
|
-
let :with_deleted_config do
|
93
|
-
test_utils.generate_config({
|
94
|
-
upstreams: []
|
95
|
-
})
|
96
|
-
end
|
97
|
-
|
98
|
-
before(:each) do
|
99
|
-
schema.commit(config, schema.scan(config))
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'deletes an upstream' do
|
103
|
-
changes = schema.scan(with_deleted_config)
|
104
|
-
|
105
|
-
expect(changes.map(&:class)).to include(KongSchema::Actions::Delete)
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'does delete an upstream' do
|
109
|
-
changes = schema.scan(with_deleted_config)
|
110
|
-
|
111
|
-
expect {
|
112
|
-
schema.commit(with_deleted_config, changes)
|
113
|
-
}.to change {
|
114
|
-
KongSchema::Client.connect(config) { Kong::Upstream.all.count }
|
115
|
-
}.from(1).to(0)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
require_relative './support/coverage' if ENV["COVERAGE"] == "1"
|
2
|
-
require_relative './support/kong_schema_test_utils'
|
3
|
-
|
4
|
-
require 'kong_schema'
|
5
|
-
|
6
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
9
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
10
|
-
# files.
|
11
|
-
#
|
12
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
13
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
14
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
15
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
16
|
-
# a separate helper file that requires the additional dependencies and performs
|
17
|
-
# the additional setup, and require it from the spec files that actually need
|
18
|
-
# it.
|
19
|
-
#
|
20
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
21
|
-
RSpec.configure do |config|
|
22
|
-
test_utils = KongSchemaTestUtils.new
|
23
|
-
|
24
|
-
config.before(:each) do
|
25
|
-
test_utils.reset_kong
|
26
|
-
end
|
27
|
-
|
28
|
-
config.after(:each) do
|
29
|
-
test_utils.reset_kong
|
30
|
-
end
|
31
|
-
|
32
|
-
# rspec-expectations config goes here. You can use an alternate
|
33
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
34
|
-
# assertions if you prefer.
|
35
|
-
config.expect_with :rspec do |expectations|
|
36
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
37
|
-
# and `failure_message` of custom matchers include text for helper methods
|
38
|
-
# defined using `chain`, e.g.:
|
39
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
40
|
-
# # => "be bigger than 2 and smaller than 4"
|
41
|
-
# ...rather than:
|
42
|
-
# # => "be bigger than 2"
|
43
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
44
|
-
end
|
45
|
-
|
46
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
47
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
48
|
-
config.mock_with :rspec do |mocks|
|
49
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
50
|
-
# a real object. This is generally recommended, and will default to
|
51
|
-
# `true` in RSpec 4.
|
52
|
-
mocks.verify_partial_doubles = true
|
53
|
-
end
|
54
|
-
|
55
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
56
|
-
# have no way to turn it off -- the option exists only for backwards
|
57
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
58
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
59
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
60
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
61
|
-
|
62
|
-
# The settings below are suggested to provide a good initial experience
|
63
|
-
# with RSpec, but feel free to customize to your heart's content.
|
64
|
-
config.filter_run_when_matching :focus
|
65
|
-
=begin
|
66
|
-
# This allows you to limit a spec run to individual examples or groups
|
67
|
-
# you care about by tagging them with `:focus` metadata. When nothing
|
68
|
-
# is tagged with `:focus`, all examples get run. RSpec also provides
|
69
|
-
# aliases for `it`, `describe`, and `context` that include `:focus`
|
70
|
-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
71
|
-
|
72
|
-
# Allows RSpec to persist some state between runs in order to support
|
73
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
74
|
-
# you configure your source control system to ignore this file.
|
75
|
-
config.example_status_persistence_file_path = "spec/examples.txt"
|
76
|
-
|
77
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
78
|
-
# recommended. For more details, see:
|
79
|
-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
80
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
81
|
-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
82
|
-
config.disable_monkey_patching!
|
83
|
-
|
84
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
85
|
-
# be too noisy due to issues in dependencies.
|
86
|
-
config.warnings = true
|
87
|
-
|
88
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
89
|
-
# file, and it's useful to allow more verbose output when running an
|
90
|
-
# individual spec file.
|
91
|
-
if config.files_to_run.one?
|
92
|
-
# Use the documentation formatter for detailed output,
|
93
|
-
# unless a formatter has already been configured
|
94
|
-
# (e.g. via a command-line flag).
|
95
|
-
config.default_formatter = "doc"
|
96
|
-
end
|
97
|
-
|
98
|
-
# Print the 10 slowest examples and example groups at the
|
99
|
-
# end of the spec run, to help surface which specs are running
|
100
|
-
# particularly slow.
|
101
|
-
config.profile_examples = 10
|
102
|
-
|
103
|
-
# Run specs in random order to surface order dependencies. If you find an
|
104
|
-
# order dependency and want to debug it, you can fix the order by providing
|
105
|
-
# the seed, which is printed after each run.
|
106
|
-
# --seed 1234
|
107
|
-
config.order = :random
|
108
|
-
|
109
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
110
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
111
|
-
# test failures related to randomization by passing the same `--seed` value
|
112
|
-
# as the one that triggered the failure.
|
113
|
-
Kernel.srand config.seed
|
114
|
-
=end
|
115
|
-
end
|
data/spec/support/coverage.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require "simplecov"
|
2
|
-
require "simplecov_compact_json"
|
3
|
-
|
4
|
-
SimpleCov.at_exit do
|
5
|
-
SimpleCov.minimum_coverage(95)
|
6
|
-
SimpleCov.maximum_coverage_drop(1)
|
7
|
-
SimpleCov.formatters = [
|
8
|
-
SimpleCov::Formatter::CompactJSON,
|
9
|
-
SimpleCov::Formatter::HTMLFormatter
|
10
|
-
]
|
11
|
-
SimpleCov.result.format!
|
12
|
-
end
|
13
|
-
|
14
|
-
SimpleCov.start do
|
15
|
-
add_filter "/.gem/"
|
16
|
-
add_filter "/bin/"
|
17
|
-
add_filter "/spec/"
|
18
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'kong_schema'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
class KongSchemaTestUtils
|
5
|
-
attr_reader :host
|
6
|
-
|
7
|
-
def initialize(host: ENV.fetch('KONG_URI', '127.0.0.1:9712'))
|
8
|
-
@host = host
|
9
|
-
end
|
10
|
-
|
11
|
-
def generate_config(config = {})
|
12
|
-
JSON.parse(JSON.dump({ admin_host: host }.merge(config)))
|
13
|
-
end
|
14
|
-
|
15
|
-
def generate_config_file(config = {}, format: :yaml)
|
16
|
-
buffer = case format
|
17
|
-
when :json
|
18
|
-
JSON.dump(config)
|
19
|
-
else
|
20
|
-
YAML.dump(config)
|
21
|
-
end
|
22
|
-
|
23
|
-
filename = case format
|
24
|
-
when :json
|
25
|
-
'config.json'
|
26
|
-
else
|
27
|
-
'config.yaml'
|
28
|
-
end
|
29
|
-
|
30
|
-
filepath = File.join(Dir.pwd, 'spec', 'fixtures', filename)
|
31
|
-
|
32
|
-
File.write(filepath, buffer)
|
33
|
-
yield filepath
|
34
|
-
ensure
|
35
|
-
FileUtils.rm(filepath)
|
36
|
-
end
|
37
|
-
|
38
|
-
def fake_stdin(*args)
|
39
|
-
$stdin = StringIO.new
|
40
|
-
$stdin.puts(args.shift) until args.empty?
|
41
|
-
$stdin.rewind
|
42
|
-
yield
|
43
|
-
ensure
|
44
|
-
$stdin = STDIN
|
45
|
-
end
|
46
|
-
|
47
|
-
def reset_kong
|
48
|
-
KongSchema::Client.purge(generate_config)
|
49
|
-
end
|
50
|
-
end
|