|
1 | 1 | require 'rack/reverse_proxy'
|
| 2 | +require 'securerandom' |
2 | 3 |
|
3 |
| -code_version = ENV.fetch('PACT_BROKER_CODE_VERSION') |
4 |
| -database_version = ENV.fetch('PACT_BROKER_DATABASE_VERSION') |
5 |
| - |
6 |
| -describe "Code version #{code_version} running against database version #{database_version}" do |
7 |
| - describe "Publishing a pact" do |
8 |
| - |
9 |
| - before do |
10 |
| - unless ENV['OK'] |
11 |
| - retries = 0 |
12 |
| - begin |
13 |
| - get "/" |
14 |
| - ENV['OK'] = 'true' |
15 |
| - rescue Errno::ECONNREFUSED => error |
16 |
| - if retries < 10 |
17 |
| - retries += 1 |
18 |
| - sleep 1 |
19 |
| - retry |
20 |
| - else |
21 |
| - raise error |
22 |
| - end |
23 |
| - end |
24 |
| - end |
| 4 | +CODE_VERSION = ENV.fetch('PACT_BROKER_CODE_VERSION') |
| 5 | +DATABASE_VERSION = ENV.fetch('PACT_BROKER_DATABASE_VERSION') |
| 6 | +CONSUMER_VERSION = CODE_VERSION == 'head' ? '100.100.100' : CODE_VERSION |
| 7 | +TAG = SecureRandom.hex |
| 8 | + |
| 9 | +describe "Code version #{CODE_VERSION} running against database version #{DATABASE_VERSION}" do |
| 10 | + |
| 11 | + before do |
| 12 | + wait_for_server_to_start |
| 13 | + end |
| 14 | + |
| 15 | + let(:path) { "/pacts/provider/Bar/consumer/Foo/version/#{CONSUMER_VERSION}" } |
| 16 | + let(:response_body_json) { JSON.parse(subject.body) } |
| 17 | + let(:pact_content) do |
| 18 | + pact = load_json_fixture('foo-bar.json') |
| 19 | + pact['interactions'][0]['providerState'] = "the code version is #{CODE_VERSION}" |
| 20 | + pact.to_json |
| 21 | + end |
| 22 | + |
| 23 | + let(:app) do |
| 24 | + Rack::ReverseProxy.new do |
| 25 | + reverse_proxy_options preserve_host: true |
| 26 | + reverse_proxy '/', "http://localhost:#{ENV.fetch('PORT')}/" |
25 | 27 | end
|
| 28 | + end |
26 | 29 |
|
27 |
| - let(:pact_content) { load_fixture('foo-bar.json') } |
28 |
| - let(:path) { "/pacts/provider/Bar/consumer/Foo/version/1.2.3" } |
29 |
| - let(:response_body_json) { JSON.parse(subject.body) } |
| 30 | + describe "tagging a consumer version" do |
| 31 | + let(:path) { "/pacticipants/Foo/versions/#{CONSUMER_VERSION}/tags/#{TAG}"} |
| 32 | + subject { put path, nil, {'CONTENT_TYPE' => 'application/json' }; last_response } |
30 | 33 |
|
31 |
| - let(:app) do |
32 |
| - Rack::ReverseProxy.new do |
33 |
| - reverse_proxy_options preserve_host: true |
34 |
| - reverse_proxy '/', "http://localhost:#{ENV.fetch('PORT')}/" |
35 |
| - end |
| 34 | + it "returns a success status" do |
| 35 | + expect(subject.status.to_s).to match /20\d/ |
36 | 36 | end
|
| 37 | + end |
37 | 38 |
|
| 39 | + describe "publishing a pact" do |
38 | 40 | subject { put path, pact_content, {'CONTENT_TYPE' => 'application/json' }; last_response }
|
39 | 41 |
|
40 |
| - |
41 | 42 | it "returns a success status" do
|
42 | 43 | expect(subject.status.to_s).to match /20\d/
|
43 | 44 | end
|
| 45 | + end |
| 46 | + |
| 47 | + describe "retrieving a pact" do |
| 48 | + subject { get path; last_response } |
| 49 | + |
| 50 | + it "returns the pact in the body" do |
| 51 | + expect(response_body_json).to include JSON.parse(pact_content) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + describe "retrieving the latest tagged pact" do |
| 56 | + let(:path) { "/pacts/provider/Bar/consumer/Foo/latest" } |
| 57 | + subject { get path; last_response } |
| 58 | + |
| 59 | + it "returns the latest pact" do |
| 60 | + expect(subject.headers['X-Pact-Consumer-Version']).to eq '100.100.100' |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + describe "retrieving the latest tagged pact" do |
| 65 | + let(:path) { "/pacts/provider/Bar/consumer/Foo/latest/#{TAG}" } |
| 66 | + subject { get path; last_response } |
44 | 67 |
|
45 | 68 | it "returns the pact in the body" do
|
46 | 69 | expect(response_body_json).to include JSON.parse(pact_content)
|
|
0 commit comments