Skip to content

Commit

Permalink
fix: remove dead code, fix bug in URL vs file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Feb 23, 2022
1 parent bbc2321 commit dcd53e0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
9 changes: 0 additions & 9 deletions native/provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <map>
#include "pact-cpp.h"
#include <vector>
#include <iostream>

using namespace Napi;

Expand All @@ -13,7 +12,6 @@ std::map<int, VerifierHandle*> handles;
std::vector<const char*> cVec;
for(size_t i = 0; i < arr.Length(); i++) {
std::string tag = arr.Get(i).As<Napi::String>().Utf8Value();
std::cout << "element: " << tag.c_str() << "\n";
char *cstr = strdup(tag.c_str());
cVec.push_back(cstr);
}
Expand Down Expand Up @@ -109,8 +107,6 @@ Napi::Value PactffiVerifierNewForApplication(const Napi::CallbackInfo& info) {
Napi::Value PactffiVerifierExecute(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();

std::cout << "Pactffiverifierexecute \n";

if (info.Length() < 1) {
throw Napi::Error::New(env, "PactffiInit(arguments) received < 1 argument");
}
Expand All @@ -119,18 +115,13 @@ Napi::Value PactffiVerifierExecute(const Napi::CallbackInfo& info) {
throw Napi::Error::New(env, "PactffiInit(arguments) expected a number");
}

std::cout << "Pactffiverifierexecute 1 \n";
// Extract arguments to verifier
size_t handle = info[0].As<Napi::Number>().Uint32Value();
std::cout << "Pactffiverifierexecute 2 \n";

// Execute the function asynchronously
Napi::Function callback = info[1].As<Napi::Function>();
std::cout << "Pactffiverifierexecute 3 \n";
VerificationWorker* verificationWorker = new VerificationWorker(callback, handle);
std::cout << "Pactffiverifierexecute 4 \n";
verificationWorker->Queue();
std::cout << "Pactffiverifierexecute 5 \n";

return info.Env().Undefined();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pact-foundation/pact-core",
"version": "13.4.1-beta.16",
"version": "13.4.1-beta.18",
"description": "Core of @pact-foundation/pact. You almost certainly don't want to depend on this directly.",
"main": "src/index.js",
"homepage": "https://github.com/pact-foundation/pact-js-core#readme",
Expand Down
4 changes: 2 additions & 2 deletions src/ffi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ export type Ffi = {
pactffiVerifierSetFilterInfo(
handle: FfiVerifierHandle,
description: string,
filterState: string,
filterNoState: boolean
state: string,
noState: boolean
): void;
pactffiVerifierSetProviderState(
handle: FfiVerifierHandle,
Expand Down
46 changes: 30 additions & 16 deletions src/verifier/nativeVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,33 @@ export const verify = (opts: VerifierOptions): Promise<string> => {
);
}

const filterDescription = process.env.PACT_DESCRIPTION || '';
const filterState = process.env.PACT_PROVIDER_STATE || '';
const filterNoState = process.env.PACT_PROVIDER_NO_STATE ? true : false;

ffi.pactffiVerifierSetFilterInfo(
handle,
filterDescription,
filterState,
filterNoState
);

if (opts.pactUrls) {
opts.pactUrls.forEach((file) => {
logger.debug(`checking source type of given pactUrl: ${file}`);
try {
new URL(file);
logger.debug(`adding ${file} as a Url source`);

ffi.pactffiVerifierUrlSource(
handle,
file,
opts.pactBrokerUsername || '',
opts.pactBrokerPassword || '',
opts.pactBrokerToken || ''
);
const u = new URL(file);

if (u.hostname) {
logger.debug(`adding ${file} as a Url source`);
ffi.pactffiVerifierUrlSource(
handle,
file,
opts.pactBrokerUsername || '',
opts.pactBrokerPassword || '',
opts.pactBrokerToken || ''
);
}
} catch {
logger.debug(`${file} is not a URI`);
}
Expand Down Expand Up @@ -90,7 +103,6 @@ export const verify = (opts: VerifierOptions): Promise<string> => {
if (
opts.publishVerificationResult ||
opts.providerVersion ||
opts.publishVerificationResult ||
opts.buildUrl ||
opts.disableSslVerification ||
opts.timeout ||
Expand All @@ -105,13 +117,15 @@ export const verify = (opts: VerifierOptions): Promise<string> => {
);
}

if (opts.pactBrokerUrl && opts.provider) {
const brokerUrl = opts.pactBrokerUrl || process.env.PACT_BROKER_BASE_URL;

if (brokerUrl && opts.provider) {
ffi.pactffiVerifierBrokerSourceWithSelectors(
handle,
opts.pactBrokerUrl,
opts.pactBrokerUsername || '',
opts.pactBrokerPassword || '',
opts.pactBrokerToken || '',
brokerUrl,
opts.pactBrokerUsername || process.env.PACT_BROKER_USERNAME || '',
opts.pactBrokerPassword || process.env.PACT_BROKER_PASSWORD || '',
opts.pactBrokerToken || process.env.PACT_BROKER_TOKEN || '',
opts.enablePending || false,
opts.includeWipPactsSince || '',
opts.providerVersionTags || [],
Expand Down

0 comments on commit dcd53e0

Please sign in to comment.