pact_broker-client 1.38.1 → 1.41.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +38 -0
- data/Gemfile +4 -0
- data/README.md +18 -0
- data/bin/pact-broker +6 -0
- data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +61 -140
- data/example/scripts/publish-pact.sh +1 -1
- data/lib/pact_broker/client/base_client.rb +1 -1
- data/lib/pact_broker/client/can_i_deploy.rb +20 -3
- data/lib/pact_broker/client/cli/broker.rb +35 -10
- data/lib/pact_broker/client/cli/record_deployment_long_desc.txt +0 -0
- data/lib/pact_broker/client/cli/version_selector_options_parser.rb +4 -0
- data/lib/pact_broker/client/colorize_notices.rb +31 -0
- data/lib/pact_broker/client/hal/entity.rb +16 -0
- data/lib/pact_broker/client/hal/http_client.rb +37 -1
- data/lib/pact_broker/client/hal/link.rb +12 -0
- data/lib/pact_broker/client/hal/links.rb +15 -0
- data/lib/pact_broker/client/hal_client_methods.rb +8 -0
- data/lib/pact_broker/client/matrix.rb +4 -0
- data/lib/pact_broker/client/matrix/abbreviate_version_number.rb +15 -0
- data/lib/pact_broker/client/matrix/resource.rb +26 -1
- data/lib/pact_broker/client/matrix/text_formatter.rb +11 -8
- data/lib/pact_broker/client/pacts.rb +0 -1
- data/lib/pact_broker/client/publish_pacts.rb +94 -128
- data/lib/pact_broker/client/publish_pacts_the_old_way.rb +194 -0
- data/lib/pact_broker/client/tasks/publication_task.rb +3 -3
- data/lib/pact_broker/client/version.rb +1 -1
- data/lib/pact_broker/client/versions/record_deployment.rb +6 -6
- data/lib/pact_broker/client/versions/record_undeployment.rb +45 -68
- data/pact-broker-client.gemspec +1 -0
- data/script/approve-all.sh +6 -0
- data/script/publish-pact.sh +36 -5
- data/script/record-deployment.sh +1 -3
- data/script/record-undeployment.sh +4 -0
- data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +13 -0
- data/spec/fixtures/foo-bar.json +31 -0
- data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +47 -5
- data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +3 -3
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +36 -7
- data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +21 -0
- data/spec/lib/pact_broker/client/hal/http_client_spec.rb +64 -7
- data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +3 -0
- data/spec/lib/pact_broker/client/{publish_pacts_spec.rb → publish_pacts_the_old_way_spec.rb} +10 -9
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +18 -12
- data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +5 -5
- data/spec/pacts/pact_broker_client-pact_broker.json +50 -124
- data/spec/service_providers/pact_broker_client_create_version_spec.rb +4 -4
- data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +98 -0
- data/spec/service_providers/publish_pacts_spec.rb +116 -0
- data/spec/service_providers/record_deployment_spec.rb +6 -7
- data/spec/spec_helper.rb +2 -1
- data/spec/support/approvals.rb +26 -0
- data/spec/support/shared_context.rb +6 -2
- metadata +41 -5
@@ -15,14 +15,14 @@ module PactBroker
|
|
15
15
|
stub_request(:get, broker_base_url).to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
|
16
16
|
end
|
17
17
|
|
18
|
-
let(:
|
18
|
+
let(:target) { "blue" }
|
19
19
|
|
20
20
|
let(:params) do
|
21
21
|
{
|
22
22
|
pacticipant_name: "Foo",
|
23
23
|
version_number: "1",
|
24
24
|
environment_name: "test",
|
25
|
-
|
25
|
+
target: target,
|
26
26
|
output: "text"
|
27
27
|
}
|
28
28
|
end
|
@@ -53,11 +53,11 @@ module PactBroker
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "indicates the API was Pactflow" do
|
56
|
-
expect(subject.message).to include "Recorded deployment of Foo version 1 to test in Pactflow"
|
56
|
+
expect(subject.message).to include "Recorded deployment of Foo version 1 to test (target blue) in Pactflow"
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
context "when
|
60
|
+
context "when target is false" do
|
61
61
|
before do
|
62
62
|
allow_any_instance_of(RecordDeployment).to receive(:check_if_command_supported)
|
63
63
|
allow_any_instance_of(RecordDeployment).to receive(:check_environment_exists)
|
@@ -65,7 +65,7 @@ module PactBroker
|
|
65
65
|
allow_any_instance_of(RecordDeployment).to receive(:pact_broker_name).and_return("")
|
66
66
|
end
|
67
67
|
|
68
|
-
let(:
|
68
|
+
let(:target) { false }
|
69
69
|
|
70
70
|
let(:deployed_version_resource) do
|
71
71
|
double('PactBroker::Client::Hal::Entity', response: double('response', headers: response_headers) )
|
@@ -1552,7 +1552,7 @@
|
|
1552
1552
|
},
|
1553
1553
|
{
|
1554
1554
|
"description": "a request for the index resource",
|
1555
|
-
"providerState": "the pb:
|
1555
|
+
"providerState": "the pb:publish-contracts relations exists in the index resource",
|
1556
1556
|
"request": {
|
1557
1557
|
"method": "GET",
|
1558
1558
|
"path": "/",
|
@@ -1567,20 +1567,13 @@
|
|
1567
1567
|
},
|
1568
1568
|
"body": {
|
1569
1569
|
"_links": {
|
1570
|
-
"pb:
|
1571
|
-
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-
|
1572
|
-
},
|
1573
|
-
"pb:environments": {
|
1574
|
-
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS"
|
1570
|
+
"pb:publish-contracts": {
|
1571
|
+
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS"
|
1575
1572
|
}
|
1576
1573
|
}
|
1577
1574
|
},
|
1578
1575
|
"matchingRules": {
|
1579
|
-
"$.body._links.pb:
|
1580
|
-
"match": "regex",
|
1581
|
-
"regex": "http:\\/\\/.*{pacticipant}.*{version}"
|
1582
|
-
},
|
1583
|
-
"$.body._links.pb:environments.href": {
|
1576
|
+
"$.body._links.pb:publish-contracts.href": {
|
1584
1577
|
"match": "regex",
|
1585
1578
|
"regex": "http:\\/\\/.*"
|
1586
1579
|
}
|
@@ -1588,86 +1581,33 @@
|
|
1588
1581
|
}
|
1589
1582
|
},
|
1590
1583
|
{
|
1591
|
-
"description": "a request
|
1592
|
-
"providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment",
|
1593
|
-
"request": {
|
1594
|
-
"method": "GET",
|
1595
|
-
"path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
|
1596
|
-
"headers": {
|
1597
|
-
"Accept": "application/hal+json"
|
1598
|
-
}
|
1599
|
-
},
|
1600
|
-
"response": {
|
1601
|
-
"status": 200,
|
1602
|
-
"headers": {
|
1603
|
-
"Content-Type": "application/hal+json;charset=utf-8"
|
1604
|
-
},
|
1605
|
-
"body": {
|
1606
|
-
"_links": {
|
1607
|
-
"pb:record-deployment": [
|
1608
|
-
{
|
1609
|
-
"name": "test",
|
1610
|
-
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST"
|
1611
|
-
}
|
1612
|
-
]
|
1613
|
-
}
|
1614
|
-
},
|
1615
|
-
"matchingRules": {
|
1616
|
-
"$.body._links.pb:record-deployment[0].href": {
|
1617
|
-
"match": "regex",
|
1618
|
-
"regex": "http:\\/\\/.*"
|
1619
|
-
}
|
1620
|
-
}
|
1621
|
-
}
|
1622
|
-
},
|
1623
|
-
{
|
1624
|
-
"description": "a request to record a deployment",
|
1625
|
-
"providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment",
|
1584
|
+
"description": "a request to publish contracts",
|
1626
1585
|
"request": {
|
1627
1586
|
"method": "POST",
|
1628
|
-
"path": "/HAL-REL-PLACEHOLDER-PB-
|
1587
|
+
"path": "/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS",
|
1629
1588
|
"headers": {
|
1630
1589
|
"Content-Type": "application/json",
|
1631
1590
|
"Accept": "application/hal+json"
|
1632
1591
|
},
|
1633
1592
|
"body": {
|
1634
|
-
"
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
"
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
"path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
|
1653
|
-
"headers": {
|
1654
|
-
"Accept": "application/hal+json"
|
1655
|
-
}
|
1656
|
-
},
|
1657
|
-
"response": {
|
1658
|
-
"status": 404,
|
1659
|
-
"headers": {
|
1660
|
-
}
|
1661
|
-
}
|
1662
|
-
},
|
1663
|
-
{
|
1664
|
-
"description": "a request for a pacticipant version",
|
1665
|
-
"providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with 2 environments that aren't test available for deployment",
|
1666
|
-
"request": {
|
1667
|
-
"method": "GET",
|
1668
|
-
"path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
|
1669
|
-
"headers": {
|
1670
|
-
"Accept": "application/hal+json"
|
1593
|
+
"pacticipantName": "Foo",
|
1594
|
+
"pacticipantVersionNumber": "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
|
1595
|
+
"branch": "main",
|
1596
|
+
"tags": [
|
1597
|
+
"dev"
|
1598
|
+
],
|
1599
|
+
"buildUrl": "http://build",
|
1600
|
+
"contracts": [
|
1601
|
+
{
|
1602
|
+
"consumerName": "Foo",
|
1603
|
+
"providerName": "Bar",
|
1604
|
+
"specification": "pact",
|
1605
|
+
"contentType": "application/json",
|
1606
|
+
"content": "eyJjb25zdW1lciI6eyJuYW1lIjoiRm9vIn0sInByb3ZpZGVyIjp7Im5hbWUiOiJCYXIifSwiaW50ZXJhY3Rpb25zIjpbeyJkZXNjcmlwdGlvbiI6ImFuIGV4YW1wbGUgcmVxdWVzdCIsInByb3ZpZGVyU3RhdGUiOiJhIHByb3ZpZGVyIHN0YXRlIiwicmVxdWVzdCI6eyJtZXRob2QiOiJHRVQiLCJwYXRoIjoiLyIsImhlYWRlcnMiOnt9fSwicmVzcG9uc2UiOnsic3RhdHVzIjoyMDAsImhlYWRlcnMiOnsiQ29udGVudC1UeXBlIjoiYXBwbGljYXRpb24vaGFsK2pzb24ifX19XSwibWV0YWRhdGEiOnsicGFjdFNwZWNpZmljYXRpb24iOnsidmVyc2lvbiI6IjIuMC4wIn19fQ==",
|
1607
|
+
"writeMode": "overwrite",
|
1608
|
+
"onConflict": "overwrite"
|
1609
|
+
}
|
1610
|
+
]
|
1671
1611
|
}
|
1672
1612
|
},
|
1673
1613
|
"response": {
|
@@ -1676,56 +1616,42 @@
|
|
1676
1616
|
"Content-Type": "application/hal+json;charset=utf-8"
|
1677
1617
|
},
|
1678
1618
|
"body": {
|
1619
|
+
"_embedded": {
|
1620
|
+
"pacticipant": {
|
1621
|
+
"name": "Foo"
|
1622
|
+
},
|
1623
|
+
"version": {
|
1624
|
+
"number": "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
|
1625
|
+
"buildUrl": "http://build"
|
1626
|
+
}
|
1627
|
+
},
|
1628
|
+
"logs": [
|
1629
|
+
{
|
1630
|
+
"level": "info",
|
1631
|
+
"message": "some message"
|
1632
|
+
}
|
1633
|
+
],
|
1679
1634
|
"_links": {
|
1680
|
-
"pb:
|
1635
|
+
"pb:pacticipant-version-tags": [
|
1681
1636
|
{
|
1682
|
-
"name": "
|
1683
|
-
|
1684
|
-
|
1637
|
+
"name": "dev"
|
1638
|
+
}
|
1639
|
+
],
|
1640
|
+
"pb:contracts": [
|
1685
1641
|
{
|
1686
|
-
"
|
1687
|
-
"href": "href"
|
1642
|
+
"href": "http://some-pact"
|
1688
1643
|
}
|
1689
1644
|
]
|
1690
1645
|
}
|
1691
1646
|
},
|
1692
1647
|
"matchingRules": {
|
1693
|
-
"$.body.
|
1694
|
-
"
|
1648
|
+
"$.body.logs": {
|
1649
|
+
"min": 1
|
1695
1650
|
},
|
1696
|
-
"$.body.
|
1651
|
+
"$.body.logs[*].*": {
|
1697
1652
|
"match": "type"
|
1698
|
-
}
|
1699
|
-
|
1700
|
-
}
|
1701
|
-
},
|
1702
|
-
{
|
1703
|
-
"description": "a request for the environments",
|
1704
|
-
"providerState": "an environment with name test exists",
|
1705
|
-
"request": {
|
1706
|
-
"method": "GET",
|
1707
|
-
"path": "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
|
1708
|
-
"headers": {
|
1709
|
-
"Accept": "application/hal+json"
|
1710
|
-
}
|
1711
|
-
},
|
1712
|
-
"response": {
|
1713
|
-
"status": 200,
|
1714
|
-
"headers": {
|
1715
|
-
"Content-Type": "application/hal+json;charset=utf-8"
|
1716
|
-
},
|
1717
|
-
"body": {
|
1718
|
-
"_links": {
|
1719
|
-
"pb:environments": [
|
1720
|
-
{
|
1721
|
-
"name": "test",
|
1722
|
-
"href": "href"
|
1723
|
-
}
|
1724
|
-
]
|
1725
|
-
}
|
1726
|
-
},
|
1727
|
-
"matchingRules": {
|
1728
|
-
"$.body._links.pb:environments[0].href": {
|
1653
|
+
},
|
1654
|
+
"$.body._links.pb:contracts[0].href": {
|
1729
1655
|
"match": "type"
|
1730
1656
|
}
|
1731
1657
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'pact_helper'
|
2
2
|
require 'pact_broker/client'
|
3
|
-
require 'pact_broker/client/
|
3
|
+
require 'pact_broker/client/publish_pacts_the_old_way'
|
4
4
|
|
5
5
|
describe PactBroker::Client::Versions, pact: true do
|
6
6
|
|
@@ -9,7 +9,7 @@ describe PactBroker::Client::Versions, pact: true do
|
|
9
9
|
|
10
10
|
describe "creating a pacticipant version" do
|
11
11
|
before do
|
12
|
-
allow(
|
12
|
+
allow(publish_pacts_the_old_way).to receive(:consumer_names).and_return(["Foo"])
|
13
13
|
allow($stdout).to receive(:puts)
|
14
14
|
end
|
15
15
|
let(:version_path) { "/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-{pacticipant}-{version}" }
|
@@ -18,11 +18,11 @@ describe PactBroker::Client::Versions, pact: true do
|
|
18
18
|
let(:branch) { "main" }
|
19
19
|
let(:build_url) { "http://my-ci/builds/1" }
|
20
20
|
let(:consumer_version_params) { { number: number, branch: branch, build_url: build_url } }
|
21
|
-
let(:
|
21
|
+
let(:publish_pacts_the_old_way) { PactBroker::Client::PublishPactsTheOldWay.new(pact_broker.mock_service_base_url, ["some-pact.json"], consumer_version_params, {}) }
|
22
22
|
let(:provider_state) { "version #{number} of pacticipant Foo does not exist" }
|
23
23
|
let(:expected_response_status) { 201 }
|
24
24
|
|
25
|
-
subject {
|
25
|
+
subject { publish_pacts_the_old_way.send(:create_consumer_versions) }
|
26
26
|
|
27
27
|
before do
|
28
28
|
pact_broker
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative 'pact_helper'
|
2
|
+
require 'pact_broker/client/can_i_deploy'
|
3
|
+
|
4
|
+
module PactBroker::Client
|
5
|
+
describe Matrix, :pact => true, skip: true do
|
6
|
+
|
7
|
+
include_context "pact broker"
|
8
|
+
|
9
|
+
describe "can-i-deploy ignoring a pacticipant version" do
|
10
|
+
let(:matrix_response_body) { matrix }
|
11
|
+
let(:matrix) do
|
12
|
+
{
|
13
|
+
"summary" => {
|
14
|
+
"deployable" => true,
|
15
|
+
"ignored" => 1
|
16
|
+
},
|
17
|
+
"notices" => Pact.each_like("text" => "some notice", "type" => "info"),
|
18
|
+
"matrix" => [
|
19
|
+
{
|
20
|
+
"consumer" => {
|
21
|
+
"name" => "Foo",
|
22
|
+
"version" => {
|
23
|
+
"number" => "1.2.3"
|
24
|
+
}
|
25
|
+
},
|
26
|
+
"provider" => {
|
27
|
+
"name" => "Bar",
|
28
|
+
"version" => {
|
29
|
+
"number" => "4.5.6"
|
30
|
+
}
|
31
|
+
},
|
32
|
+
"verificationResult" => {
|
33
|
+
"success" => true,
|
34
|
+
"_links" => {
|
35
|
+
"self" => {
|
36
|
+
"href" => Pact.like("http://result")
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
},{
|
41
|
+
"consumer" => {
|
42
|
+
"name" => "Foo",
|
43
|
+
"version" => {
|
44
|
+
"number" => "3.4.5"
|
45
|
+
}
|
46
|
+
},
|
47
|
+
"provider" => {
|
48
|
+
"name" => "Bar",
|
49
|
+
"version" => {
|
50
|
+
"number" => "4.5.6"
|
51
|
+
}
|
52
|
+
},
|
53
|
+
"verificationResult" => {
|
54
|
+
"success" => false,
|
55
|
+
"_links" => {
|
56
|
+
"self" => {
|
57
|
+
"href" => Pact.like("http://result")
|
58
|
+
}
|
59
|
+
}
|
60
|
+
},
|
61
|
+
"ignored" => true
|
62
|
+
}
|
63
|
+
]
|
64
|
+
}
|
65
|
+
|
66
|
+
end
|
67
|
+
let(:selectors) { [{ pacticipant: "Bar", version: "4.5.6" }, { pacticipant: "Foo", tag: "prod" } ] }
|
68
|
+
let(:matrix_options) do
|
69
|
+
{
|
70
|
+
ignore_selectors: [{ pacticipant: "Foo", version: "3.4.5" }]
|
71
|
+
}
|
72
|
+
end
|
73
|
+
let(:options) { { retry_while_unknown: 0, output: 'table' } }
|
74
|
+
|
75
|
+
before do
|
76
|
+
pact_broker
|
77
|
+
.given("provider Bar version 4.5.6 has a successful verification for Foo version 1.2.3 tagged prod and a failed verification for version 3.4.5 tagged prod")
|
78
|
+
.upon_receiving("a request to determine if Bar can be deployed with all Foo tagged prod, ignoring the verification for Foo version 3.4.5")
|
79
|
+
.with(
|
80
|
+
method: :get,
|
81
|
+
path: "/matrix",
|
82
|
+
query: "q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=4.5.6&q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Btag%5D=prod&latestby=cvpv&ignore%5B%5D%5Bpacticipant%5D=Foo&ignore%5B%5D%5Bversion%5D=3.4.5"
|
83
|
+
)
|
84
|
+
.will_respond_with(
|
85
|
+
status: 200,
|
86
|
+
headers: pact_broker_response_headers,
|
87
|
+
body: matrix_response_body
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
subject { PactBroker::Client::CanIDeploy.call(broker_base_url, selectors, matrix_options, options, {})}
|
92
|
+
|
93
|
+
it 'returns the CLI output' do
|
94
|
+
Approvals.verify(subject.message, :name => "can_i_deploy_ignore", format: :txt)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'pact_broker/client/publish_pacts'
|
2
|
+
require 'service_providers/pact_helper'
|
3
|
+
|
4
|
+
RSpec.describe "publishing contracts", pact: true do
|
5
|
+
before do
|
6
|
+
allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
|
7
|
+
allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
|
8
|
+
end
|
9
|
+
include_context "pact broker"
|
10
|
+
include PactBrokerPactHelperMethods
|
11
|
+
|
12
|
+
let(:pacticipant_name) { "Foo" }
|
13
|
+
let(:version_number) { "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30" }
|
14
|
+
let(:output) { "text" }
|
15
|
+
let(:build_url) { "http://build" }
|
16
|
+
let(:consumer_version_params) do
|
17
|
+
{
|
18
|
+
pacticipant_name: pacticipant_name,
|
19
|
+
number: version_number,
|
20
|
+
tags: ["dev"],
|
21
|
+
branch: "main",
|
22
|
+
build_url: build_url,
|
23
|
+
output: output
|
24
|
+
}
|
25
|
+
end
|
26
|
+
let(:pact_file_path_1) { "spec/fixtures/foo-bar.json" }
|
27
|
+
let(:pact_file_paths) { [pact_file_path_1] }
|
28
|
+
let(:options) { {} }
|
29
|
+
let(:pact_broker_client_options) { {} }
|
30
|
+
let(:expected_content) { Base64.strict_encode64(JSON.parse(File.read(pact_file_path_1)).to_json) }
|
31
|
+
let(:request_body) do
|
32
|
+
{
|
33
|
+
pacticipantName: pacticipant_name,
|
34
|
+
pacticipantVersionNumber: version_number,
|
35
|
+
branch: "main",
|
36
|
+
tags: ["dev"],
|
37
|
+
buildUrl: "http://build",
|
38
|
+
contracts: [
|
39
|
+
{
|
40
|
+
consumerName: pacticipant_name,
|
41
|
+
providerName: "Bar",
|
42
|
+
specification: "pact",
|
43
|
+
contentType: "application/json",
|
44
|
+
content: expected_content,
|
45
|
+
writeMode: "overwrite",
|
46
|
+
onConflict: "overwrite"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
subject { PactBroker::Client::PublishPacts.call(broker_base_url, pact_file_paths, consumer_version_params, options, pact_broker_client_options) }
|
53
|
+
|
54
|
+
def mock_index
|
55
|
+
pact_broker
|
56
|
+
.given("the pb:publish-contracts relations exists in the index resource")
|
57
|
+
.upon_receiving("a request for the index resource")
|
58
|
+
.with(
|
59
|
+
method: "GET",
|
60
|
+
path: '/',
|
61
|
+
headers: get_request_headers).
|
62
|
+
will_respond_with(
|
63
|
+
status: 200,
|
64
|
+
headers: pact_broker_response_headers,
|
65
|
+
body: {
|
66
|
+
_links: {
|
67
|
+
:'pb:publish-contracts' => {
|
68
|
+
href: placeholder_url_term("pb:publish-contracts")
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def mock_contract_publication
|
76
|
+
pact_broker
|
77
|
+
.upon_receiving("a request to publish contracts")
|
78
|
+
.with(
|
79
|
+
method: "POST",
|
80
|
+
path: '/HAL-REL-PLACEHOLDER-PB-PUBLISH-CONTRACTS',
|
81
|
+
headers: post_request_headers,
|
82
|
+
body: request_body).
|
83
|
+
will_respond_with(
|
84
|
+
status: 200,
|
85
|
+
headers: pact_broker_response_headers,
|
86
|
+
body: {
|
87
|
+
_embedded: {
|
88
|
+
pacticipant: {
|
89
|
+
name: pacticipant_name
|
90
|
+
},
|
91
|
+
version: {
|
92
|
+
number: version_number,
|
93
|
+
buildUrl: build_url
|
94
|
+
}
|
95
|
+
},
|
96
|
+
logs: Pact.each_like(level: "info", message: "some message"),
|
97
|
+
_links: {
|
98
|
+
:'pb:pacticipant-version-tags' => [{ name: "dev"} ],
|
99
|
+
:'pb:contracts' => [{ href: Pact.like("http://some-pact") }]
|
100
|
+
}
|
101
|
+
}
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with valid params" do
|
106
|
+
before do
|
107
|
+
mock_index
|
108
|
+
mock_contract_publication
|
109
|
+
end
|
110
|
+
|
111
|
+
it "returns a success result" do
|
112
|
+
expect(subject.success).to be true
|
113
|
+
expect(subject.message).to include "some message"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|