Skip to content

Commit

Permalink
Merge pull request #412 from pact-foundation/adamwitko-add-no-fail-if…
Browse files Browse the repository at this point in the history
…-no-pacts

Adamwitko add no fail if no pacts
  • Loading branch information
mefellows authored Oct 18, 2022
2 parents 48257da + 577e49f commit b11da94
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 5 deletions.
3 changes: 2 additions & 1 deletion native/addon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "pactffiVerifierSetFilterInfo"), Napi::Function::New(env, PactffiVerifierSetFilterInfo));
exports.Set(Napi::String::New(env, "pactffiVerifierSetProviderState"), Napi::Function::New(env, PactffiVerifierSetProviderState));
exports.Set(Napi::String::New(env, "pactffiVerifierSetConsumerFilters"), Napi::Function::New(env, PactffiVerifierSetConsumerFilters));
exports.Set(Napi::String::New(env, "pactffiVerifierSetFailIfNoPactsFound"), Napi::Function::New(env, PactffiVerifierSetFailIfNoPactsFound));
exports.Set(Napi::String::New(env, "pactffiVerifierAddCustomHeader"), Napi::Function::New(env, PactffiVerifierAddCustomHeader));
exports.Set(Napi::String::New(env, "pactffiVerifierAddFileSource"), Napi::Function::New(env, PactffiVerifierAddFileSource));
exports.Set(Napi::String::New(env, "pactffiVerifierAddDirectorySource"), Napi::Function::New(env, PactffiVerifierAddDirectorySource));
Expand All @@ -66,4 +67,4 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
return exports;
}

NODE_API_MODULE(pact, Init)
NODE_API_MODULE(pact, Init)
33 changes: 33 additions & 0 deletions native/provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,39 @@ Napi::Value PactffiVerifierSetConsumerFilters(const Napi::CallbackInfo& info) {
return info.Env().Undefined();
}


/**
* Set the provider to fail or pass if no pacts can be found.
*
* C interface:
*
* void pactffi_verifier_set_no_pacts_is_error(VerifierHandle *handle,
* unsigned char is_error);
*
*/
Napi::Value PactffiVerifierSetFailIfNoPactsFound(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
if (info.Length() < 2) {
throw Napi::Error::New(env, "PactffiVerifierSetFailIfNoPactsFound received < 2 arguments");
}

if (!info[0].IsNumber()) {
throw Napi::Error::New(env, "pactffiVerifierSetFailIfNoPactsFound(arg 0) expected a VerifierHandle");
}

if (!info[1].IsBoolean()) {
throw Napi::Error::New(env, "pactffiVerifierSetFailIfNoPactsFound(arg 1) expected a boolean");
}

uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
bool failIfNoPactsFound = info[1].As<Napi::Boolean>().Value();

pactffi_verifier_set_no_pacts_is_error(handles[handleId], failIfNoPactsFound);

return info.Env().Undefined();
}


/**
* Adds a custom header to be added to the requests made to the provider.
*
Expand Down
3 changes: 2 additions & 1 deletion native/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Napi::Value PactffiVerifierAddDirectorySource(const Napi::CallbackInfo& info);
Napi::Value PactffiVerifierUrlSource(const Napi::CallbackInfo& info);
// Napi::Value PactffiVerifierBrokerSource(const Napi::CallbackInfo& info);
Napi::Value PactffiVerifierBrokerSourceWithSelectors(const Napi::CallbackInfo& info);
Napi::Value PactffiVerifierSetFailIfNoPactsFound(const Napi::CallbackInfo& info);
// Unimplemented
// Napi::Value PactffiVerifierShutdown(const Napi::CallbackInfo& info);
// Napi::Value PactffiVerifierNewForApplication(const Napi::CallbackInfo& info);
Expand All @@ -35,4 +36,4 @@ Napi::Value PactffiVerifierBrokerSourceWithSelectors(const Napi::CallbackInfo& i
// Napi::Value PactffiVerifierExecute(const Napi::CallbackInfo& info);
// Napi::Value PactffiVerifierCliArgs(const Napi::CallbackInfo& info);
// Napi::Value PactffiVerifierLogs(const Napi::CallbackInfo& info);
// Napi::Value PactffiVerifierLogsForProvider(const Napi::CallbackInfo& info);
// Napi::Value PactffiVerifierLogsForProvider(const Napi::CallbackInfo& info);
4 changes: 4 additions & 0 deletions src/ffi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ export type FfiVerificationFunctions = {
handle: FfiVerifierHandle,
consumers: string[]
): void;
pactffiVerifierSetFailIfNoPactsFound(
handle: FfiVerifierHandle,
failIfNoPactsFound: boolean
): void;
pactffiVerifierAddCustomHeader(
handle: FfiVerifierHandle,
header: string,
Expand Down
19 changes: 16 additions & 3 deletions src/verifier/argumentMapper/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export const orderOfExecution: OrderedExecution = {
pactffiVerifierSetVerificationOptions: 4,
pactffiVerifierSetPublishOptions: 5,
pactffiVerifierSetConsumerFilters: 6,
pactffiVerifierAddCustomHeader: 7,
pactffiVerifierAddDirectorySource: 8,
pactffiVerifierBrokerSourceWithSelectors: 9,
pactffiVerifierSetFailIfNoPactsFound: 7,
pactffiVerifierAddCustomHeader: 8,
pactffiVerifierAddDirectorySource: 9,
pactffiVerifierBrokerSourceWithSelectors: 10,
};

export type MergedFfiSourceFunctions = {
Expand Down Expand Up @@ -177,6 +178,18 @@ export const ffiFnMapping: FnMapping<
return { status: FnValidationStatus.IGNORE };
},
},
pactffiVerifierSetFailIfNoPactsFound: {
validateAndExecute(ffi, handle, options) {
if (options.failIfNoPactsFound !== undefined) {
ffi.pactffiVerifierSetFailIfNoPactsFound(
handle,
options.failIfNoPactsFound
);
return { status: FnValidationStatus.SUCCESS };
}
return { status: FnValidationStatus.IGNORE };
},
},
pactffiVerifierSetFilterInfo: {
validateAndExecute(ffi, handle) {
if (
Expand Down
1 change: 1 addition & 0 deletions src/verifier/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface VerifierOptions {
* @deprecated use providerVersionBranch instead
*/
providerBranch?: string;
failIfNoPactsFound?: boolean;
}

/** These are the deprecated verifier options, removed prior to this verison,
Expand Down
1 change: 1 addition & 0 deletions src/verifier/validateOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export const validationRules: ArgumentValidationRules<InternalPactVerifierOption
monkeypatch: [deprecatedFunction],
logDir: [deprecatedFunction],
consumerFilters: [wrapCheckType(checkTypes.assert.nonEmptyString)],
failIfNoPactsFound: [wrapCheckType(checkTypes.assert.boolean)],
};

export const validateOptions = (options: VerifierOptions): VerifierOptions => {
Expand Down

0 comments on commit b11da94

Please sign in to comment.