diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..aa0823b35 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3' + +services: + + postgres: + image: postgres + healthcheck: + test: psql postgres --command "select 1" -U postgres + ports: + - "5432:5432" + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: postgres + + broker_app: + image: dius/pact-broker + ports: + - "80:80" + links: + - postgres + environment: + PACT_BROKER_DATABASE_USERNAME: postgres + PACT_BROKER_DATABASE_PASSWORD: password + PACT_BROKER_DATABASE_HOST: postgres + PACT_BROKER_DATABASE_NAME: postgres diff --git a/examples/e2e/test/provider.spec.js b/examples/e2e/test/provider.spec.js index a6f35e1c0..1c7002539 100644 --- a/examples/e2e/test/provider.spec.js +++ b/examples/e2e/test/provider.spec.js @@ -1,67 +1,60 @@ -const { - Verifier -} = require('../../../dist/pact') -const path = require('path') -const chai = require('chai') -const chaiAsPromised = require('chai-as-promised') -const expect = chai.expect -const { - VerifierOptions -} = require('@pact-foundation/pact-node'); -chai.use(chaiAsPromised) -const { - server, - importData, - animalRepository -} = require('../provider.js') +const { Verifier } = require("../../../dist/pact"); +const path = require("path"); +const chai = require("chai"); +const chaiAsPromised = require("chai-as-promised"); +const expect = chai.expect; +const { VerifierOptions } = require("@pact-foundation/pact-node"); +chai.use(chaiAsPromised); +const { server, importData, animalRepository } = require("../provider.js"); -server.post('/setup', (req, res) => { - const state = req.body.state +server.post("/setup", (req, res) => { + const state = req.body.state; - animalRepository.clear() + animalRepository.clear(); switch (state) { - case 'Has no animals': + case "Has no animals": // do nothing - break + break; default: - importData() + importData(); } - res.end() -}) + res.end(); +}); server.listen(8081, () => { - console.log('Animal Profile Service listening on http://localhost:8081') -}) + console.log("Animal Profile Service listening on http://localhost:8081"); +}); // Verify that the provider meets all consumer expectations -describe('Pact Verification', () => { - it('should validate the expectations of Matching Service', function () { // lexical binding required here - this.timeout(10000) +describe("Pact Verification", () => { + it("should validate the expectations of Matching Service", function() { + // lexical binding required here + this.timeout(10000); let opts = { - provider: 'Animal Profile Service', - providerBaseUrl: 'http://localhost:8081', - providerStatesSetupUrl: 'http://localhost:8081/setup', + provider: "Animal Profile Service", + providerBaseUrl: "http://localhost:8081", + providerStatesSetupUrl: "http://localhost:8081/setup", // Fetch pacts from broker - pactBrokerUrl: 'https://test.pact.dius.com.au/', + // pactBrokerUrl: 'https://test.pact.dius.com.au/', + pactBrokerUrl: "http://localhost", // Fetch from broker with given tags - tags: ['prod', 'sit5'], + tags: ["prod", "sit5"], // Specific Remote pacts (doesn't need to be a broker) // pactFilesOrDirs: ['https://test.pact.dius.com.au/pacts/provider/Animal%20Profile%20Service/consumer/Matching%20Service/latest'], // Local pacts // pactFilesOrDirs: [path.resolve(process.cwd(), './pacts/matching_service-animal_profile_service.json')], - pactBrokerUsername: 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M', - pactBrokerPassword: 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1', + pactBrokerUsername: "dXfltyFMgNOFZAxr8io9wJ37iUpY42M", + pactBrokerPassword: "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", publishVerificationResult: true, providerVersion: "1.0.0", - customProviderHeaders: ['Authorization: basic e5e5e5e5e5e5e5'] - } + customProviderHeaders: ["Authorization: basic e5e5e5e5e5e5e5"] + }; - return new Verifier().verifyProvider(opts) - .then(output => { - console.log('Pact Verification Complete!') - console.log(output) - }) - }) -}) + return new Verifier().verifyProvider(opts).then(output => { + console.log("Pact Verification Complete!"); + console.log(output); + }); + }); +}); diff --git a/examples/e2e/test/publish.js b/examples/e2e/test/publish.js index 55c5edd24..14e87704d 100644 --- a/examples/e2e/test/publish.js +++ b/examples/e2e/test/publish.js @@ -1,23 +1,34 @@ -const pact = require('@pact-foundation/pact-node') -const path = require('path') +const pact = require("@pact-foundation/pact-node"); +const path = require("path"); const opts = { - pactFilesOrDirs: [path.resolve(__dirname, '../pacts/matching_service-animal_profile_service.json')], - pactBroker: 'https://test.pact.dius.com.au', - pactBrokerUsername: 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M', - pactBrokerPassword: 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1', - tags: ['prod', 'test'], - consumerVersion: '1.0.' + ((process.env.TRAVIS_BUILD_NUMBER) ? process.env.TRAVIS_BUILD_NUMBER : Math.floor(new Date() / 1000)) -} + pactFilesOrDirs: [ + path.resolve( + __dirname, + "../pacts/matching_service-animal_profile_service.json" + ) + ], + // pactBroker: 'https://test.pact.dius.com.au', + pactBroker: "http://localhost", + pactBrokerUsername: "dXfltyFMgNOFZAxr8io9wJ37iUpY42M", + pactBrokerPassword: "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", + tags: ["prod", "test"], + consumerVersion: + "1.0." + + (process.env.TRAVIS_BUILD_NUMBER + ? process.env.TRAVIS_BUILD_NUMBER + : Math.floor(new Date() / 1000)) +}; -pact.publishPacts(opts) +pact + .publishPacts(opts) .then(() => { - console.log('Pact contract publishing complete!') - console.log('') - console.log('Head over to https://test.pact.dius.com.au/ and login with') - console.log('=> Username: dXfltyFMgNOFZAxr8io9wJ37iUpY42M') - console.log('=> Password: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1') - console.log('to see your published contracts.') + console.log("Pact contract publishing complete!"); + console.log(""); + console.log("Head over to https://test.pact.dius.com.au/ and login with"); + console.log("=> Username: dXfltyFMgNOFZAxr8io9wJ37iUpY42M"); + console.log("=> Password: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"); + console.log("to see your published contracts."); }) .catch(e => { - console.log('Pact contract publishing failed: ', e) - }) + console.log("Pact contract publishing failed: ", e); + });