diff --git a/native/addon.cc b/native/addon.cc index e3c20509..635244ca 100644 --- a/native/addon.cc +++ b/native/addon.cc @@ -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)); @@ -66,4 +67,4 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { return exports; } -NODE_API_MODULE(pact, Init) \ No newline at end of file +NODE_API_MODULE(pact, Init) diff --git a/native/provider.cc b/native/provider.cc index ad779f44..7d6f4547 100644 --- a/native/provider.cc +++ b/native/provider.cc @@ -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().Uint32Value(); + bool failIfNoPactsFound = info[1].As().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. * diff --git a/native/provider.h b/native/provider.h index c69c34f8..01020fec 100644 --- a/native/provider.h +++ b/native/provider.h @@ -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); @@ -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); \ No newline at end of file +// Napi::Value PactffiVerifierLogsForProvider(const Napi::CallbackInfo& info); diff --git a/src/ffi/types.ts b/src/ffi/types.ts index a119841a..8a1aa7f8 100644 --- a/src/ffi/types.ts +++ b/src/ffi/types.ts @@ -320,6 +320,10 @@ export type FfiVerificationFunctions = { handle: FfiVerifierHandle, consumers: string[] ): void; + pactffiVerifierSetFailIfNoPactsFound( + handle: FfiVerifierHandle, + failIfNoPactsFound: boolean + ): void; pactffiVerifierAddCustomHeader( handle: FfiVerifierHandle, header: string, diff --git a/src/verifier/argumentMapper/arguments.ts b/src/verifier/argumentMapper/arguments.ts index 1d58db33..746317eb 100644 --- a/src/verifier/argumentMapper/arguments.ts +++ b/src/verifier/argumentMapper/arguments.ts @@ -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 = { @@ -177,6 +178,18 @@ export const ffiFnMapping: FnMapping< return { status: FnValidationStatus.IGNORE }; }, }, + pactffiVerifierSetFailIfNoPactsFound: { + validateAndExecute(ffi, handle, options) { + if (options.failIfNoPactsFound) { + ffi.pactffiVerifierSetFailIfNoPactsFound( + handle, + options.failIfNoPactsFound + ); + return { status: FnValidationStatus.SUCCESS }; + } + return { status: FnValidationStatus.IGNORE }; + }, + }, pactffiVerifierSetFilterInfo: { validateAndExecute(ffi, handle) { if ( diff --git a/src/verifier/types.ts b/src/verifier/types.ts index 3ae94626..7789d914 100644 --- a/src/verifier/types.ts +++ b/src/verifier/types.ts @@ -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, diff --git a/src/verifier/validateOptions.ts b/src/verifier/validateOptions.ts index e35a3a4e..ce2716e1 100644 --- a/src/verifier/validateOptions.ts +++ b/src/verifier/validateOptions.ts @@ -243,6 +243,7 @@ export const validationRules: ArgumentValidationRules {