pact_broker-client 1.59.0 → 1.60.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release_gem.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/lib/pact_broker/client/merge_pacts.rb +21 -10
- data/lib/pact_broker/client/version.rb +1 -1
- data/spec/lib/pact_broker/client/merge_pacts_spec.rb +146 -43
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cd60c123fbe4481515d784d73f97296280109f50252c150c1c0c083813cb34b
|
4
|
+
data.tar.gz: 3b8371bd71d74a2b9ada1b3ba2d54a24f5ae6349ce2c6a44075e72546f6dbf6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 828e7e3d9eae551b586bff597b7229c5174ab4000fda79cab8567163b7b3c7443c535c35f504f530dc611bee0708240e27a8756bd394f5b9780047b3f8fc2391
|
7
|
+
data.tar.gz: 9d64d148a588d7aa240decdab057c2352409944036d35f6d7ff67a18f673107b7324d383a96bdaaa67b14e837556d04b87f91b5126c77e8103e4a3cffd153ff2
|
data/CHANGELOG.md
CHANGED
@@ -18,29 +18,40 @@ module PactBroker
|
|
18
18
|
def merge original, additional
|
19
19
|
new_pact = JSON.parse(original.to_json, symbolize_names: true)
|
20
20
|
|
21
|
-
additional
|
21
|
+
merge_interactions_or_messages(new_pact, original, additional, :interactions)
|
22
|
+
merge_interactions_or_messages(new_pact, original, additional, :messages)
|
23
|
+
|
24
|
+
new_pact
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def merge_interactions_or_messages(new_pact, original, additional, key)
|
30
|
+
return unless additional[key] || original[key]
|
31
|
+
|
32
|
+
additional_messages_or_interactions = additional[key] || []
|
33
|
+
original_messages_or_interactions = original[key] || []
|
34
|
+
new_pact[key] ||= []
|
35
|
+
|
36
|
+
additional_messages_or_interactions.each do |new_interaction|
|
22
37
|
# check to see if this interaction matches an existing interaction
|
23
|
-
overwrite_index =
|
38
|
+
overwrite_index = original_messages_or_interactions.find_index do |original_interaction|
|
24
39
|
same_description_and_state?(original_interaction, new_interaction)
|
25
40
|
end
|
26
41
|
|
27
42
|
# overwrite existing interaction if a match is found, otherwise appends the new interaction
|
28
43
|
if overwrite_index
|
29
|
-
if new_interaction ==
|
30
|
-
new_pact[
|
44
|
+
if new_interaction == original_messages_or_interactions[overwrite_index]
|
45
|
+
new_pact[key][overwrite_index] = new_interaction
|
31
46
|
else
|
32
|
-
raise PactMergeError, almost_duplicate_message(
|
47
|
+
raise PactMergeError, almost_duplicate_message(original_messages_or_interactions[overwrite_index], new_interaction)
|
33
48
|
end
|
34
49
|
else
|
35
|
-
new_pact[
|
50
|
+
new_pact[key] << new_interaction
|
36
51
|
end
|
37
52
|
end
|
38
|
-
|
39
|
-
new_pact
|
40
53
|
end
|
41
54
|
|
42
|
-
private
|
43
|
-
|
44
55
|
def almost_duplicate_message(original, new_interaction)
|
45
56
|
"Two interactions have been found with same description (#{new_interaction[:description].inspect}) and provider state (#{new_interaction[:providerState].inspect}) but a different request or response. " +
|
46
57
|
"Please use a different description or provider state, or hard-code any random data.\n\n" +
|
@@ -4,63 +4,166 @@ module PactBroker
|
|
4
4
|
module Client
|
5
5
|
describe MergePacts do
|
6
6
|
describe ".call" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
describe "with a pact with interactions" do
|
8
|
+
let(:pact_hash_1) do
|
9
|
+
{
|
10
|
+
other: 'info',
|
11
|
+
interactions: [
|
12
|
+
{ providerState: 1, description: 1, foo: 'bar' }
|
13
|
+
]
|
14
|
+
}
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
let(:pact_hash_2) do
|
18
|
+
{
|
19
|
+
interactions: [
|
20
|
+
{ providerState: 2, description: 2, foo: 'wiffle' }
|
21
|
+
]
|
22
|
+
}
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
let(:pact_hash_3) do
|
26
|
+
{
|
27
|
+
interactions: [
|
28
|
+
{ providerState: 3, description: 3, foo: 'meep' },
|
29
|
+
{ providerState: 1, description: 1, foo: 'bar' }
|
30
|
+
]
|
31
|
+
}
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
|
35
|
+
|
36
|
+
let(:expected_merge) do
|
37
|
+
{
|
38
|
+
other: 'info',
|
39
|
+
interactions: [
|
40
|
+
{ providerState: 1, description: 1, foo: 'bar' },
|
41
|
+
{ providerState: 2, description: 2, foo: 'wiffle' },
|
42
|
+
{ providerState: 3, description: 3, foo: 'meep' }
|
43
|
+
]
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
subject { MergePacts.call(pact_hashes) }
|
45
48
|
|
46
|
-
|
49
|
+
it "merges the interactions by consumer/provider" do
|
50
|
+
expect(subject).to eq expected_merge
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when an interaction is found with the same state and description but has a difference elsewhere" do
|
54
|
+
let(:pact_hash_3) do
|
55
|
+
{
|
56
|
+
interactions: [
|
57
|
+
{ providerState: 3, description: 3, foo: 'meep' },
|
58
|
+
{ providerState: 1, description: 1, foo: 'different' }
|
59
|
+
]
|
60
|
+
}
|
61
|
+
end
|
47
62
|
|
48
|
-
|
49
|
-
|
63
|
+
it "raises an error" do
|
64
|
+
expect { subject }.to raise_error PactMergeError, /foo.*different/
|
65
|
+
end
|
66
|
+
end
|
50
67
|
end
|
51
68
|
|
52
|
-
|
69
|
+
describe "with a pact with messages" do
|
70
|
+
let(:pact_hash_1) do
|
71
|
+
{
|
72
|
+
other: 'info',
|
73
|
+
messages: [
|
74
|
+
{ providerState: 1, description: 1, foo: 'bar' }
|
75
|
+
]
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:pact_hash_2) do
|
80
|
+
{
|
81
|
+
messages: [
|
82
|
+
{ providerState: 2, description: 2, foo: 'wiffle' }
|
83
|
+
]
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
53
87
|
let(:pact_hash_3) do
|
88
|
+
{
|
89
|
+
messages: [
|
90
|
+
{ providerState: 3, description: 3, foo: 'meep' },
|
91
|
+
{ providerState: 1, description: 1, foo: 'bar' }
|
92
|
+
]
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
|
97
|
+
|
98
|
+
let(:expected_merge) do
|
99
|
+
{
|
100
|
+
other: 'info',
|
101
|
+
messages: [
|
102
|
+
{ providerState: 1, description: 1, foo: 'bar' },
|
103
|
+
{ providerState: 2, description: 2, foo: 'wiffle' },
|
104
|
+
{ providerState: 3, description: 3, foo: 'meep' }
|
105
|
+
]
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
subject { MergePacts.call(pact_hashes) }
|
110
|
+
|
111
|
+
it "merges the messages by consumer/provider" do
|
112
|
+
expect(subject).to eq expected_merge
|
113
|
+
end
|
114
|
+
|
115
|
+
context "when an interaction is found with the same state and description but has a difference elsewhere" do
|
116
|
+
let(:pact_hash_3) do
|
117
|
+
{
|
118
|
+
messages: [
|
119
|
+
{ providerState: 3, description: 3, foo: 'meep' },
|
120
|
+
{ providerState: 1, description: 1, foo: 'different' }
|
121
|
+
]
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
125
|
+
it "raises an error" do
|
126
|
+
expect { subject }.to raise_error PactMergeError, /foo.*different/
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "with a pact with messages and a pact with interactions" do
|
132
|
+
let(:pact_hash_1) do
|
133
|
+
{
|
134
|
+
other: 'info',
|
135
|
+
messages: [
|
136
|
+
{ providerState: 1, description: 1, foo: 'bar' }
|
137
|
+
]
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
let(:pact_hash_2) do
|
54
142
|
{
|
55
143
|
interactions: [
|
56
|
-
{providerState:
|
57
|
-
{providerState: 1, description: 1, foo: 'different' }
|
144
|
+
{ providerState: 2, description: 2, foo: 'wiffle' }
|
58
145
|
]
|
59
146
|
}
|
60
147
|
end
|
61
148
|
|
62
|
-
|
63
|
-
|
149
|
+
let(:pact_hashes) { [pact_hash_1, pact_hash_2] }
|
150
|
+
|
151
|
+
let(:expected_merge) do
|
152
|
+
{
|
153
|
+
other: 'info',
|
154
|
+
messages: [
|
155
|
+
{ providerState: 1, description: 1, foo: 'bar' }
|
156
|
+
],
|
157
|
+
interactions: [
|
158
|
+
{ providerState: 2, description: 2, foo: 'wiffle' }
|
159
|
+
]
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
subject { MergePacts.call(pact_hashes) }
|
164
|
+
|
165
|
+
it "merges the messages by consumer/provider" do
|
166
|
+
expect(subject).to eq expected_merge
|
64
167
|
end
|
65
168
|
end
|
66
169
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.60.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beth Skurrie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03
|
11
|
+
date: 2022-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -425,7 +425,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
425
425
|
- !ruby/object:Gem::Version
|
426
426
|
version: '0'
|
427
427
|
requirements: []
|
428
|
-
rubygems_version: 3.3.
|
428
|
+
rubygems_version: 3.3.12
|
429
429
|
signing_key:
|
430
430
|
specification_version: 4
|
431
431
|
summary: See description
|