pact_broker 2.69.0 → 2.70.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +62 -0
  3. data/CHANGELOG.md +16 -0
  4. data/DEVELOPER_SETUP.md +6 -0
  5. data/Dockerfile +4 -3
  6. data/Gemfile +4 -0
  7. data/ISSUES.md +23 -0
  8. data/config/database.yml +14 -0
  9. data/docker-compose-issue-repro.yml +11 -7
  10. data/lib/pact_broker/api/resources/clean.rb +36 -0
  11. data/lib/pact_broker/api/resources/group.rb +5 -1
  12. data/lib/pact_broker/db/clean.rb +4 -1
  13. data/lib/pact_broker/db/clean_incremental.rb +78 -0
  14. data/lib/pact_broker/domain/tag.rb +69 -8
  15. data/lib/pact_broker/domain/verification.rb +6 -0
  16. data/lib/pact_broker/domain/version.rb +35 -1
  17. data/lib/pact_broker/logging.rb +7 -0
  18. data/lib/pact_broker/matrix/unresolved_selector.rb +8 -0
  19. data/lib/pact_broker/pacts/all_pact_publications.rb +1 -3
  20. data/lib/pact_broker/pacts/pact_publication.rb +7 -1
  21. data/lib/pact_broker/pacts/repository.rb +4 -2
  22. data/lib/pact_broker/tasks/clean_task.rb +28 -12
  23. data/lib/pact_broker/test/http_test_data_builder.rb +52 -5
  24. data/lib/pact_broker/version.rb +1 -1
  25. data/lib/pact_broker/webhooks/triggered_webhook.rb +6 -0
  26. data/pact_broker.gemspec +1 -1
  27. data/script/docker/db-start.sh +1 -1
  28. data/script/reproduce-issue.rb +38 -15
  29. data/spec/fixtures/approvals/modifiable_resources.approved.json +3 -0
  30. data/spec/lib/pact_broker/api/resources/group_spec.rb +9 -7
  31. data/spec/lib/pact_broker/db/clean_incremental_spec.rb +93 -0
  32. data/spec/lib/pact_broker/domain/tag_spec.rb +46 -0
  33. data/spec/lib/pact_broker/domain/verification_spec.rb +13 -0
  34. data/spec/lib/pact_broker/domain/version_spec.rb +23 -0
  35. data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +3 -1
  36. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +14 -1
  37. metadata +20 -6
@@ -4,17 +4,13 @@ require 'pact_broker/groups/service'
4
4
  require 'rack/test'
5
5
 
6
6
  module PactBroker::Api
7
-
8
7
  module Resources
9
-
10
8
  describe Group do
11
-
12
9
  include Rack::Test::Methods
13
10
 
14
11
  let(:app) { PactBroker::API }
15
12
 
16
13
  describe "GET" do
17
-
18
14
  let(:group) { double('group') }
19
15
  let(:decorator) { instance_double(PactBroker::Api::Decorators::RelationshipsCsvDecorator) }
20
16
  let(:csv) { 'csv' }
@@ -60,7 +56,6 @@ module PactBroker::Api
60
56
  subject
61
57
  expect(last_response.body).to eq csv
62
58
  end
63
-
64
59
  end
65
60
 
66
61
  context "when the pacticipant does not exist" do
@@ -72,9 +67,16 @@ module PactBroker::Api
72
67
  end
73
68
  end
74
69
 
75
- end
70
+ context "when there is no group because the pacticipant isn't integrated with any other pacticipants" do
71
+ let(:group) { nil }
76
72
 
73
+ it "returns an empty body" do
74
+ expect(subject.status).to eq 200
75
+ expect(last_response.headers['Content-Type']).to eq 'text/csv;charset=utf-8'
76
+ expect(subject.body).to eq ""
77
+ end
78
+ end
79
+ end
77
80
  end
78
81
  end
79
-
80
82
  end
@@ -0,0 +1,93 @@
1
+ require 'pact_broker/db/clean_incremental'
2
+ require 'pact_broker/matrix/unresolved_selector'
3
+
4
+ IS_MYSQL = !!DB.mysql?
5
+
6
+ module PactBroker
7
+ module DB
8
+ # Inner queries don't work on MySQL. Seriously, MySQL???
9
+ describe CleanIncremental, pending: IS_MYSQL do
10
+
11
+ def pact_publication_count_for(consumer_name, version_number)
12
+ PactBroker::Pacts::PactPublication.where(consumer_version: PactBroker::Domain::Version.where_pacticipant_name(consumer_name).where(number: version_number)).count
13
+ end
14
+
15
+ let(:options) { {} }
16
+ let(:db) { PactBroker::DB.connection }
17
+
18
+ subject { CleanIncremental.call(PactBroker::DB.connection, options) }
19
+ let(:latest_dev_selector) { PactBroker::Matrix::UnresolvedSelector.new(tag: "dev", latest: true) }
20
+ let(:all_prod_selector) { PactBroker::Matrix::UnresolvedSelector.new(tag: "prod") }
21
+ let(:limit) { 3 }
22
+
23
+ describe ".call"do
24
+ context "when there are specified versions to keep" do
25
+ before do
26
+ td.create_pact_with_hierarchy("Foo", "1", "Bar")
27
+ .create_consumer_version_tag("prod").comment("keep as one of prod")
28
+ .create_consumer_version_tag("dev")
29
+ .add_day
30
+ .create_consumer_version("2").comment("DELETE")
31
+ .add_day
32
+ .create_consumer_version("3", tag_names: %w{prod}).comment("keep as one of prod")
33
+ .create_pact
34
+ .add_day
35
+ .create_consumer_version("4", tag_names: %w{dev}).comment("DELETE as not latest")
36
+ .create_pact
37
+ .add_day
38
+ .create_consumer_version("5", tag_names: %w{dev}).comment("keep as latest dev")
39
+ .create_pact
40
+ .add_day
41
+ .create_consumer_version("6", tag_names: %w{foo}).comment("DELETE as not specified")
42
+ .create_pact
43
+ .add_day
44
+ .create_consumer_version("7").comment("keep as deletion limit is 3")
45
+ .create_pact
46
+ end
47
+
48
+ let(:options) { { keep: [all_prod_selector, latest_dev_selector], limit: limit } }
49
+
50
+ it "does not delete the consumer versions specified" do
51
+ expect(PactBroker::Domain::Version.where(number: "1").count).to be 1
52
+ expect(PactBroker::Domain::Version.where(number: "2").count).to be 1
53
+ expect(PactBroker::Domain::Version.where(number: "3").count).to be 1
54
+ expect(PactBroker::Domain::Version.where(number: "4").count).to be 1
55
+ expect(PactBroker::Domain::Version.where(number: "5").count).to be 1
56
+ expect(PactBroker::Domain::Version.where(number: "6").count).to be 1
57
+ expect(PactBroker::Domain::Version.where(number: "7").count).to be 1
58
+ subject
59
+ expect(PactBroker::Domain::Version.where(number: "1").count).to be 1
60
+ expect(PactBroker::Domain::Version.where(number: "2").count).to be 0
61
+ expect(PactBroker::Domain::Version.where(number: "3").count).to be 1
62
+ expect(PactBroker::Domain::Version.where(number: "4").count).to be 0
63
+ expect(PactBroker::Domain::Version.where(number: "5").count).to be 1
64
+ expect(PactBroker::Domain::Version.where(number: "6").count).to be 0
65
+ expect(PactBroker::Domain::Version.where(number: "7").count).to be 1
66
+ end
67
+ end
68
+
69
+ context "with orphan pact versions" do
70
+ before do
71
+ # Create a pact that will not be deleted
72
+ td.create_pact_with_hierarchy("Foo", "0", "Bar", json_content_1)
73
+ .create_consumer_version_tag("dev")
74
+ # Create an orphan pact version
75
+ pact_version_params = PactBroker::Pacts::PactVersion.first.to_hash
76
+ pact_version_params.delete(:id)
77
+ pact_version_params[:sha] = "1234"
78
+ PactBroker::Pacts::PactVersion.create(pact_version_params)
79
+ end
80
+
81
+ let(:json_content_1) { { interactions: ['a', 'b']}.to_json }
82
+ let(:json_content_2) { { interactions: ['a', 'c']}.to_json }
83
+
84
+ let(:options) { { keep: [latest_dev_selector] } }
85
+
86
+ it "deletes them" do
87
+ expect { subject }.to change { PactBroker::Pacts::PactVersion.count }.by(-1)
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,46 @@
1
+ require 'pact_broker/domain/tag'
2
+
3
+ module PactBroker
4
+ module Domain
5
+ describe Tag do
6
+ before do
7
+ td.create_consumer("foo")
8
+ .create_consumer_version("1")
9
+ .create_consumer_version_tag("dev")
10
+ .create_consumer_version_tag("prod")
11
+ .create_consumer_version("2")
12
+ .create_consumer_version_tag("dev")
13
+ .create_consumer_version_tag("bloop")
14
+ .create_consumer_version("3")
15
+ .create_consumer_version_tag("dev")
16
+ .create_consumer("bar")
17
+ .create_consumer_version("1")
18
+ .create_consumer_version_tag("test")
19
+ end
20
+
21
+ it "returns the latest tags for the given pacticipant ids" do
22
+ pacticipant = PactBroker::Domain::Pacticipant.order(:id).first
23
+ tags = Tag.latest_tags_for_pacticipant_ids([pacticipant.id]).all
24
+ expect(tags.collect(&:name).sort).to eq %w{bloop dev prod}
25
+ expect(tags.find{ |t| t.name == "dev" }.version.number).to eq "3"
26
+ expect(tags.find{ |t| t.name == "prod" }.version.number).to eq "1"
27
+ expect(tags.find{ |t| t.name == "bloop" }.version.number).to eq "2"
28
+ expect(tags.collect(&:version_id).compact.size).to eq 3
29
+ expect(tags.collect(&:created_at).compact.size).to eq 3
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ # Table: tags
36
+ # Primary Key: (name, version_id)
37
+ # Columns:
38
+ # name | text |
39
+ # version_id | integer |
40
+ # created_at | timestamp without time zone | NOT NULL
41
+ # updated_at | timestamp without time zone | NOT NULL
42
+ # Indexes:
43
+ # tags_pk | PRIMARY KEY btree (version_id, name)
44
+ # ndx_tag_name | btree (name)
45
+ # Foreign key constraints:
46
+ # tags_version_id_fkey | (version_id) REFERENCES versions(id)
@@ -4,6 +4,19 @@ module PactBroker
4
4
 
5
5
  module Domain
6
6
  describe Verification do
7
+ describe "delete" do
8
+ before do
9
+ td.create_pact_with_hierarchy("Foo", "1", "Bar")
10
+ .create_verification_webhook
11
+ .create_verification(provider_version: "2")
12
+ .create_triggered_webhook
13
+ .create_webhook_execution
14
+ end
15
+
16
+ it "deletes stuff" do
17
+ Verification.delete
18
+ end
19
+ end
7
20
 
8
21
  describe "#save" do
9
22
  let!(:verification) do
@@ -172,6 +172,29 @@ module PactBroker
172
172
  .to raise_error(Sequel::UniqueConstraintViolation)
173
173
  end
174
174
  end
175
+
176
+ describe "tags_with_latest_flag" do
177
+ before do
178
+ td.create_consumer("foo")
179
+ .create_consumer_version("1")
180
+ .create_consumer_version_tag("dev")
181
+ .create_consumer_version_tag("prod")
182
+ .create_consumer_version("2")
183
+ .create_consumer_version_tag("dev")
184
+ end
185
+
186
+ it "uneager loads" do
187
+ version = Version.first(number: "1")
188
+ expect(version.tags.collect(&:name).sort).to eq %w{dev prod}
189
+ expect(version.tags_with_latest_flag.select(&:latest).collect(&:name)).to eq %w{prod}
190
+ end
191
+
192
+ it "eager loads" do
193
+ version = Version.eager(:tags, :tags_with_latest_flag).where(number: "1").all.first
194
+ expect(version.tags.collect(&:name).sort).to eq %w{dev prod}
195
+ expect(version.tags_with_latest_flag.select(&:latest).collect(&:name)).to eq %w{prod}
196
+ end
197
+ end
175
198
  end
176
199
  end
177
200
  end
@@ -113,9 +113,11 @@ module PactBroker
113
113
  .create_pact
114
114
  .create_consumer_version("5.6.7")
115
115
  .create_consumer_version_tag("no")
116
+ .create_consumer("Foo2")
117
+ .create_consumer_version("3.4.5")
118
+ .create_consumer_version_tag("yes", comment: "actually no, just here to make sure it selects the right one")
116
119
  end
117
120
 
118
- let(:td) { TestDataBuilder.new }
119
121
  let(:pact_publication) { PactPublication.find(id: td.pact.id) }
120
122
 
121
123
  context "when the pact is the latest for a tag" do
@@ -228,17 +228,30 @@ module PactBroker
228
228
  end
229
229
  end
230
230
 
231
- context "when the provider tag does not exist yet" do
231
+ context "when the provider tag does not exist yet and there are no provider versions" do
232
232
  before do
233
233
  td.create_pact_with_hierarchy("foo", "1", "bar")
234
234
  .create_consumer_version_tag("feat-x")
235
235
  end
236
236
 
237
+ it "is included" do
238
+ expect(subject.size).to be 1
239
+ end
240
+ end
241
+
242
+ context "when the provider tag does not exist yet but there are other provider versions" do
243
+ before do
244
+ td.create_pact_with_hierarchy("foo", "1", "bar")
245
+ .create_consumer_version_tag("feat-x")
246
+ .create_provider_version("1")
247
+ end
248
+
237
249
  it "doesn't return any pacts" do
238
250
  expect(subject.size).to be 0
239
251
  end
240
252
  end
241
253
 
254
+
242
255
  context "when a pact was published between the first creation date of two provider tags" do
243
256
  let(:provider_tags) { %w[dev feat-1] }
244
257
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.69.0
4
+ version: 2.70.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bethany Skurrie
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-11-24 00:00:00.000000000 Z
13
+ date: 2020-11-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -174,16 +174,22 @@ dependencies:
174
174
  name: pact-support
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - '='
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '1.16'
180
+ - - ">="
178
181
  - !ruby/object:Gem::Version
179
- version: 1.15.0
182
+ version: 1.16.4
180
183
  type: :runtime
181
184
  prerelease: false
182
185
  version_requirements: !ruby/object:Gem::Requirement
183
186
  requirements:
184
- - - '='
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: '1.16'
190
+ - - ">="
185
191
  - !ruby/object:Gem::Version
186
- version: 1.15.0
192
+ version: 1.16.4
187
193
  - !ruby/object:Gem::Dependency
188
194
  name: padrino-core
189
195
  requirement: !ruby/object:Gem::Requirement
@@ -367,6 +373,7 @@ files:
367
373
  - ".github/ISSUE_TEMPLATE.md"
368
374
  - ".github/PULL_REQUEST_TEMPLATE.md"
369
375
  - ".github/workflows/release_gem.yml"
376
+ - ".github/workflows/test.yml"
370
377
  - ".gitignore"
371
378
  - ".rspec"
372
379
  - ".rubocop.yml"
@@ -379,6 +386,7 @@ files:
379
386
  - DEVELOPER_SETUP.md
380
387
  - Dockerfile
381
388
  - Gemfile
389
+ - ISSUES.md
382
390
  - LICENSE.txt
383
391
  - MATRIX.md
384
392
  - README.md
@@ -648,6 +656,7 @@ files:
648
656
  - lib/pact_broker/api/resources/can_i_deploy.rb
649
657
  - lib/pact_broker/api/resources/can_i_deploy_badge.rb
650
658
  - lib/pact_broker/api/resources/can_i_deploy_pacticipant_version.rb
659
+ - lib/pact_broker/api/resources/clean.rb
651
660
  - lib/pact_broker/api/resources/dashboard.rb
652
661
  - lib/pact_broker/api/resources/default_base_resource.rb
653
662
  - lib/pact_broker/api/resources/error_handler.rb
@@ -711,6 +720,7 @@ files:
711
720
  - lib/pact_broker/date_helper.rb
712
721
  - lib/pact_broker/db.rb
713
722
  - lib/pact_broker/db/clean.rb
723
+ - lib/pact_broker/db/clean_incremental.rb
714
724
  - lib/pact_broker/db/data_migrations/delete_deprecated_webhook_executions.rb
715
725
  - lib/pact_broker/db/data_migrations/helpers.rb
716
726
  - lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
@@ -1217,6 +1227,7 @@ files:
1217
1227
  - spec/lib/pact_broker/config/save_spec.rb
1218
1228
  - spec/lib/pact_broker/config/space_delimited_string_list_spec.rb
1219
1229
  - spec/lib/pact_broker/configuration_spec.rb
1230
+ - spec/lib/pact_broker/db/clean_incremental_spec.rb
1220
1231
  - spec/lib/pact_broker/db/clean_old_spec.rb
1221
1232
  - spec/lib/pact_broker/db/clean_spec.rb
1222
1233
  - spec/lib/pact_broker/db/data_migrations/migrate_webhook_headers_spec.rb
@@ -1234,6 +1245,7 @@ files:
1234
1245
  - spec/lib/pact_broker/domain/order_versions_spec.rb
1235
1246
  - spec/lib/pact_broker/domain/pact_spec.rb
1236
1247
  - spec/lib/pact_broker/domain/pacticipant_spec.rb
1248
+ - spec/lib/pact_broker/domain/tag_spec.rb
1237
1249
  - spec/lib/pact_broker/domain/verification_spec.rb
1238
1250
  - spec/lib/pact_broker/domain/version_spec.rb
1239
1251
  - spec/lib/pact_broker/domain/webhook_request_spec.rb
@@ -1612,6 +1624,7 @@ test_files:
1612
1624
  - spec/lib/pact_broker/config/save_spec.rb
1613
1625
  - spec/lib/pact_broker/config/space_delimited_string_list_spec.rb
1614
1626
  - spec/lib/pact_broker/configuration_spec.rb
1627
+ - spec/lib/pact_broker/db/clean_incremental_spec.rb
1615
1628
  - spec/lib/pact_broker/db/clean_old_spec.rb
1616
1629
  - spec/lib/pact_broker/db/clean_spec.rb
1617
1630
  - spec/lib/pact_broker/db/data_migrations/migrate_webhook_headers_spec.rb
@@ -1629,6 +1642,7 @@ test_files:
1629
1642
  - spec/lib/pact_broker/domain/order_versions_spec.rb
1630
1643
  - spec/lib/pact_broker/domain/pact_spec.rb
1631
1644
  - spec/lib/pact_broker/domain/pacticipant_spec.rb
1645
+ - spec/lib/pact_broker/domain/tag_spec.rb
1632
1646
  - spec/lib/pact_broker/domain/verification_spec.rb
1633
1647
  - spec/lib/pact_broker/domain/version_spec.rb
1634
1648
  - spec/lib/pact_broker/domain/webhook_request_spec.rb