Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Oct 8, 2018
1 parent 15706cc commit e4dd40a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 63 deletions.
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
83 changes: 38 additions & 45 deletions examples/e2e/test/provider.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
47 changes: 29 additions & 18 deletions examples/e2e/test/publish.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit e4dd40a

Please sign in to comment.