Skip to content

Commit

Permalink
Merge pull request #219 from pact-foundation/fix/issue-218
Browse files Browse the repository at this point in the history
feat: deprecate consumerVersionTag and providerVersionTag. Fixes #218
  • Loading branch information
TimothyJones authored Apr 10, 2020
2 parents c691162 + 00c66e9 commit 491b5ba
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ pact.verifyPacts({
| `pactBrokerUrl` | false | string | Base URL of the Pact Broker from which to retrieve the pacts. Required if `pactUrls` not given. |
| `provider` | false | string | Name of the provider if fetching from a Broker |
| `consumerVersionSelectors` | false | ConsumerVersionSelector\|array | Use [Selectors](https://docs.pact.io/selectors) to is a way we specify which pacticipants and versions we want to use when configuring verifications. |
| `consumerVersionTag` | false | string\|array | Retrieve the latest pacts with given tag(s) |
| `providerVersionTag` | false | string\|array | Tag(s) to apply to the provider application |
| `consumerVersionTags` | false | string\|array | Retrieve the latest pacts with given tag(s) |
| `providerVersionTags` | false | string\|array | Tag(s) to apply to the provider application |
| `includeWipPactsSince` | false | string | Includes pact marked as WIP since this date. String in the format %Y-%m-%d or %Y-%m-%dT%H:%M:%S.000%:z |
| `pactUrls` | false | array | Array of local pact file paths or HTTP-based URLs. Required if _not_ using a Pact Broker. |
| `providerStatesSetupUrl` | false | string | URL to send PUT requests to setup a given provider state |
Expand Down
74 changes: 66 additions & 8 deletions src/verifier.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import path = require('path');
import chai = require('chai');
import chaiAsPromised = require('chai-as-promised');
import verifierFactory, { VerifierOptions } from './verifier';
import verifierFactory, {
VerifierOptions,
DeprecatedVerifierOptions,
} from './verifier';

const expect = chai.expect;
chai.use(chaiAsPromised);
Expand Down Expand Up @@ -57,7 +60,7 @@ describe('Verifier Spec', () => {
expect(() =>
verifierFactory({
providerStatesSetupUrl: 'http://foo/provider-states/setup',
} as VerifierOptions),
} as VerifierOptions & DeprecatedVerifierOptions),
).to.throw(Error);
});
});
Expand Down Expand Up @@ -271,7 +274,7 @@ describe('Verifier Spec', () => {
});
});

context('when consumerVersionTag is not provided', () => {
context('when consumerVersionTags is not provided', () => {
it('should not fail', () => {
expect(() =>
verifierFactory({
Expand All @@ -282,6 +285,17 @@ describe('Verifier Spec', () => {
});
});

context('when consumerVersionTags is provided as a string', () => {
it('should convert the argument to an array', () => {
const v = verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
consumerVersionTags: 'tag-1',
});

expect(v.options.consumerVersionTags).to.deep.eq(['tag-1']);
});
});
context('when consumerVersionTag is provided as a string', () => {
it('should convert the argument to an array', () => {
const v = verifierFactory({
Expand All @@ -294,19 +308,35 @@ describe('Verifier Spec', () => {
});
});

context('when consumerVersionTag is provided as an array', () => {
context('when consumerVersionTags is provided as an array', () => {
it('should not fail', () => {
expect(() =>
verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
consumerVersionTag: ['tag-1'],
consumerVersionTags: ['tag-1'],
}),
).to.not.throw(Error);
});
});

context('when providerVersionTag is not provided', () => {
context(
'when consumerVersionTags and consumerVersionTag are provided',
() => {
it('should fail', () => {
expect(() => {
verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
consumerVersionTags: ['tag-1'],
consumerVersionTag: ['tag-1'],
});
}).to.throw(Error);
});
},
);

context('when providerVersionTags is not provided', () => {
it('should not fail', () => {
expect(() =>
verifierFactory({
Expand All @@ -317,6 +347,18 @@ describe('Verifier Spec', () => {
});
});

context('when providerVersionTags is provided as a string', () => {
it('should convert the argument to an array', () => {
const v = verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
providerVersionTags: 'tag-1',
});

expect(v.options.providerVersionTags).to.deep.eq(['tag-1']);
});
});

context('when providerVersionTag is provided as a string', () => {
it('should convert the argument to an array', () => {
const v = verifierFactory({
Expand All @@ -329,18 +371,34 @@ describe('Verifier Spec', () => {
});
});

context('when providerVersionTag is provided as an array', () => {
context('when providerVersionTags is provided as an array', () => {
it('should not fail', () => {
expect(() =>
verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
providerVersionTag: ['tag-1'],
providerVersionTags: ['tag-1'],
}),
).to.not.throw(Error);
});
});

context(
'when providerVersionTags and providerVersionTag are provided',
() => {
it('should fail', () => {
expect(() => {
verifierFactory({
providerBaseUrl: 'http://localhost',
pactUrls: [path.dirname(currentDir)],
providerVersionTags: ['tag-1'],
providerVersionTag: ['tag-1'],
});
}).to.throw(Error);
});
},
);

context('when using a bearer token', () => {
context('and specifies a username or password', () => {
it('should fail with an error', () => {
Expand Down
69 changes: 61 additions & 8 deletions src/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Verifier {
'Create function will be removed in future release, please use the default export function or use `new Verifier()`',
);

public readonly options: VerifierOptions;
public readonly options: VerifierOptions & DeprecatedVerifierOptions;
private readonly __argMapping = {
pactUrls: DEFAULT_ARG,
providerBaseUrl: '--provider-base-url',
Expand All @@ -31,6 +31,8 @@ export class Verifier {
pactBrokerToken: '--broker-token',
consumerVersionTag: '--consumer-version-tag',
providerVersionTag: '--provider-version-tag',
consumerVersionTags: '--consumer-version-tag',
providerVersionTags: '--provider-version-tag',
consumerVersionSelector: '--consumer-version-selector',
publishVerificationResult: '--publish-verification-results',
providerVersion: '--provider-app-version',
Expand All @@ -44,7 +46,7 @@ export class Verifier {
out: '--out',
};

constructor(options: VerifierOptions) {
constructor(options: VerifierOptions & DeprecatedVerifierOptions) {
options = options || {};
options.pactBrokerUrl = options.pactBrokerUrl || '';
options.pactUrls = options.pactUrls || [];
Expand All @@ -53,8 +55,44 @@ export class Verifier {
options.timeout = options.timeout || 30000;
options.consumerVersionTag = options.consumerVersionTag || [];
options.providerVersionTag = options.providerVersionTag || [];
options.consumerVersionTags = options.consumerVersionTags || [];
options.providerVersionTags = options.providerVersionTags || [];
options.consumerVersionSelector = options.consumerVersionSelector || [];

if (
!_.isEmpty(options.consumerVersionTag) &&
!_.isEmpty(options.consumerVersionTags)
) {
throw new Error(
"Must not use both 'consumerVersionTags' and 'consumerVersionTag'. Please use 'consumerVersionTags' instead",
);
}

if (
!_.isEmpty(options.providerVersionTag) &&
!_.isEmpty(options.providerVersionTags)
) {
throw new Error(
"Must not use both 'providerVersionTags' and 'providerVersionTag'. Please use 'providerVersionTags' instead",
);
}

if (
options.consumerVersionTags &&
checkTypes.string(options.consumerVersionTags)
) {
options.consumerVersionTags = [options.consumerVersionTags as string];
}
checkTypes.assert.array.of.string(options.consumerVersionTags);

if (
options.providerVersionTags &&
checkTypes.string(options.providerVersionTags)
) {
options.providerVersionTags = [options.providerVersionTags as string];
}
checkTypes.assert.array.of.string(options.providerVersionTags);

if (
options.consumerVersionTag &&
checkTypes.string(options.consumerVersionTag)
Expand All @@ -71,6 +109,14 @@ export class Verifier {
}
checkTypes.assert.array.of.string(options.providerVersionTag);

if (
!_.isEmpty(options.consumerVersionTag) ||
!_.isEmpty(options.providerVersionTag)
) {
logger.warn(
"'consumerVersionTag' and 'providerVersionTag' have been deprecated, please use 'consumerVersionTags' or 'providerVersionTags' instead",
);

if (options.includeWipPactsSince !== undefined) {
checkTypes.assert.nonEmptyString(options.includeWipPactsSince);
}
Expand Down Expand Up @@ -183,7 +229,7 @@ export class Verifier {

if (options.tags) {
logger.warn(
"'tags' has been deprecated as at v8.0.0, please use 'consumerVersionTag' instead",
"'tags' has been deprecated as at v8.0.0, please use 'consumerVersionTags' instead",
);
}

Expand Down Expand Up @@ -229,7 +275,9 @@ export class Verifier {
}

// Creates a new instance of the pact server with the specified option
export default (options: VerifierOptions): Verifier => new Verifier(options);
export default (
options: VerifierOptions & DeprecatedVerifierOptions,
): Verifier => new Verifier(options);

// A ConsumerVersionSelector is a way we specify which pacticipants and
// versions we want to use when configuring verifications.
Expand All @@ -248,22 +296,27 @@ export interface VerifierOptions {
provider?: string;
pactUrls?: string[];
pactBrokerUrl?: string;
providerStatesSetupUrl?: string;
pactBrokerUsername?: string;
pactBrokerPassword?: string;
pactBrokerToken?: string;
consumerVersionTag?: string | string[];
providerVersionTag?: string | string[];
consumerVersionTags?: string | string[];
providerVersionTags?: string | string[];
consumerVersionSelector?: ConsumerVersionSelector[];
customProviderHeaders?: string[];
publishVerificationResult?: boolean;
providerVersion?: string;
enablePending?: boolean;
timeout?: number;
tags?: string[];
verbose?: boolean;
includeWipPactsSince?: string;
monkeypatch?: string;
format?: 'json' | 'xml' | 'progress' | 'RspecJunitFormatter';
out?: string;
}

export interface DeprecatedVerifierOptions {
consumerVersionTag?: string | string[];
providerStatesSetupUrl?: string;
providerVersionTag?: string | string[];
tags?: string[];
}

0 comments on commit 491b5ba

Please sign in to comment.