Skip to content

Commit

Permalink
feat: Add new branch consumerVersionSelector options to verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwitko committed Oct 27, 2021
1 parent a8dff18 commit c3872be
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ ConsumerVersionSelector {
released?: boolean;
environment?: string;
fallbackTag?: string;
branch?: string;
mainBranch?: boolean;
matchingBranch?: boolean;
}
```

Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@types/node": "9.4.6",
"@types/promise-timeout": "^1.3.0",
"@types/rimraf": "^2.0.2",
"@types/sinon": "^9.0.11",
"@types/tar": "^4.0.3",
"@types/underscore": "1.8.7",
"@types/unixify": "^1.0.0",
Expand Down
3 changes: 3 additions & 0 deletions src/verifier/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export interface ConsumerVersionSelector {
released?: boolean;
environment?: string;
fallbackTag?: string;
branch?: string;
mainBranch?: boolean;
matchingBranch?: boolean;
}

export interface VerifierOptions {
Expand Down
64 changes: 63 additions & 1 deletion src/verifier/validateOptions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import path = require('path');
import chai = require('chai');
import chaiAsPromised = require('chai-as-promised');
import * as sinon from 'sinon';
import logger from '../logger';
import { validateOptions } from './validateOptions';
import { VerifierOptions } from './types';
import { ConsumerVersionSelector, VerifierOptions } from './types';

const expect = chai.expect;
chai.use(chaiAsPromised);
Expand Down Expand Up @@ -318,4 +320,64 @@ describe('Verifier argument validator', () => {
});
});
});

context('when providing consumerVersionSelectors', () => {
context('and an unsupported selector is specified', () => {
it('should fail with an error', () => {
expect(() =>
validateOptions({
providerBaseUrl: 'http://localhost',
pactUrls: ['http://idontexist'],
consumerVersionSelectors: [
{ unsupportedFlag: true } as ConsumerVersionSelector,
],
})
).to.throw(Error);
});
});
});

context('and the tag of "latest" is specified', () => {
it('should log out a warning that using this selector is not recommended', () => {
const warnSpy = sinon.spy(logger, 'warn');

expectSuccessWith({
providerBaseUrl: 'http://localhost',
pactUrls: ['http://idontexist'],
consumerVersionSelectors: [{ tag: 'latest' }],
});

expect(
warnSpy.calledWith(
"Using the tag 'latest' is not recommended and probably does not do what you intended."
)
).to.be.ok;
});
});

context('and valid selectors are specified', () => {
[
{ tag: 'a-tag' },
{ latest: true },
{ consumer: 'the-consumer' },
{ deployedOrReleased: true },
{ deployed: true },
{ released: true },
{ environment: 'an-environment' },
{ fallbackTag: 'a-fallback-tag' },
{ branch: 'the-branch' },
{ mainBranch: false },
{ matchingBranch: true },
].forEach((consumerVersionSelector) => {
it(`should not fail when consumerVersionSelectors is ${JSON.stringify(
consumerVersionSelector
)}`, () => {
expectSuccessWith({
providerBaseUrl: 'http://localhost',
pactUrls: ['http://idontexist'],
consumerVersionSelectors: [consumerVersionSelector],
});
});
});
});
});
4 changes: 3 additions & 1 deletion src/verifier/validateOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export const validateOptions = (o: VerifierOptions): VerifierOptions => {
'released',
'environment',
'fallbackTag',
'latest',
'branch',
'mainBranch',
'matchingBranch',
];
options.consumerVersionSelectors.forEach((selector) => {
if (selector.tag === 'latest') {
Expand Down

0 comments on commit c3872be

Please sign in to comment.