Skip to content

Commit

Permalink
test: renable plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Jun 19, 2024
1 parent 42f2662 commit 813d9a4
Show file tree
Hide file tree
Showing 13 changed files with 647 additions and 176 deletions.
1 change: 1 addition & 0 deletions script/ci/unpack-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ ls -1 artifact
mkdir -p prebuilds
mv artifact*/*.tar.gz . || echo "no mac prebuilds"
ls *.gz |xargs -n1 tar -xzf
"$SCRIPT_DIR"/../download-plugins.sh
"$SCRIPT_DIR"/build-and-test.sh
3 changes: 2 additions & 1 deletion script/download-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running

. "${SCRIPT_DIR}/lib/export-binary-versions.sh"
"${SCRIPT_DIR}/lib/download-ffi.sh"
"${SCRIPT_DIR}/lib/download-ffi.sh"
"${SCRIPT_DIR}/lib/download-plugins.sh"
6 changes: 6 additions & 0 deletions script/download-plugins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -eu
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running

. "${SCRIPT_DIR}/lib/export-binary-versions.sh"
"${SCRIPT_DIR}/install-plugin-cli.sh"
$HOME/.pact/bin/pact-plugin-cli install -y https://github.com/mefellows/pact-matt-plugin/releases/tag/$PACT_PLUGIN_MATT_VERSION
55 changes: 55 additions & 0 deletions script/install-plugin-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh -e
#
# Usage:
# $ curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh | bash
# or
# $ wget -q https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh -O- | bash
#
set -e # Needed for Windows bash, which doesn't read the shebang

detect_osarch() {
# detect_musl
case $(uname -sm) in
'Linux x86_64')
os='linux'
arch='x86_64'
;;
'Linux aarch64')
os='linux'
arch='aarch64'
;;
'Darwin x86' | 'Darwin x86_64')
os='osx'
arch='x86_64'
;;
'Darwin arm64')
os='osx'
arch='aarch64'
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
os="windows"
arch='x86_64'
ext='.exe'
;;
*)
echo "Sorry, you'll need to install the plugin CLI manually."
exit 1
;;
esac
}


VERSION="0.1.2"
detect_osarch

if [ ! -f ~/.pact/bin/pact-plugin-cli ]; then
echo "--- 🐿 Installing plugins CLI version '${VERSION}' (from tag ${TAG})"
mkdir -p ~/.pact/bin
DOWNLOAD_LOCATION=https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${VERSION}/pact-plugin-cli-${os}-${arch}${ext}.gz
echo " Downloading from: ${DOWNLOAD_LOCATION}"
curl -L -o ~/.pact/bin/pact-plugin-cli-${os}-${arch}.gz "${DOWNLOAD_LOCATION}"
echo " Downloaded $(file ~/.pact/bin/pact-plugin-cli-${os}-${arch}.gz)"
gunzip -f ~/.pact/bin/pact-plugin-cli-${os}-${arch}.gz
mv ~/.pact/bin/pact-plugin-cli-${os}-${arch} ~/.pact/bin/pact-plugin-cli
chmod +x ~/.pact/bin/pact-plugin-cli
fi
3 changes: 2 additions & 1 deletion script/lib/export-binary-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running
PROJECT_DIR="${LIB_DIR}"/../../

export FFI_VERSION=v$(grep "PACT_FFI_VERSION = '" "$PROJECT_DIR"/src/ffi/index.ts | grep -E -o "'(.*)'" | cut -d"'" -f2)
export FFI_VERSION=v$(grep "PACT_FFI_VERSION = '" "$PROJECT_DIR"/src/ffi/index.ts | grep -E -o "'(.*)'" | cut -d"'" -f2)
export PACT_PLUGIN_MATT_VERSION=v0.1.1
167 changes: 77 additions & 90 deletions test/consumer.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ const { expect } = chai;

const HOST = '127.0.0.1';

const isWin = process.platform === 'win32';
const isLinux = process.platform === 'linux';
const isDarwinArm64 = process.platform === 'darwin' && process.arch === 'arm64';
const isDarwinX64 = process.platform === 'darwin' && process.arch === 'x64';
const isCirrusCi = process.env['CIRRUS_CI'] === 'true';
const usesOctetStream =
isWin ||
isDarwinArm64 ||
(isCirrusCi && isLinux) ||
(isCirrusCi && isDarwinX64);

describe('FFI integration test for the HTTP Consumer API', () => {
setLogLevel('trace');
Expand Down Expand Up @@ -82,9 +72,7 @@ describe('FFI integration test for the HTTP Consumer API', () => {
.request({
baseURL: `http://${HOST}:${port}`,
headers: {
'content-type': usesOctetStream
? 'application/octet-stream'
: 'application/gzip',
'content-type': 'application/gzip',
Accept: 'application/json',
'x-special-header': 'header',
},
Expand Down Expand Up @@ -202,7 +190,7 @@ describe('FFI integration test for the HTTP Consumer API', () => {
interaction.withQuery('someParam', 0, 'someValue');
interaction.withRequestBinaryBody(
bytes,
usesOctetStream ? 'application/octet-stream' : 'application/gzip'
'application/gzip'
);
interaction.withResponseBody(
JSON.stringify({
Expand All @@ -218,16 +206,12 @@ describe('FFI integration test for the HTTP Consumer API', () => {
port = pact.createMockServer(HOST);
});

// TODO: find out what's going on here. Suspect binary matching has changed in the core?
// See https://github.com/pact-foundation/pact-reference/issues/171
it('generates a pact with success', () =>
axios
.request({
baseURL: `http://${HOST}:${port}`,
headers: {
'content-type': usesOctetStream
? 'application/octet-stream'
: 'application/gzip',
'content-type': 'application/gzip',
Accept: 'application/json',
'x-special-header': 'header',
},
Expand Down Expand Up @@ -262,78 +246,81 @@ describe('FFI integration test for the HTTP Consumer API', () => {
});

// Should only run this if the plugin is installed
describe.skip('using a plugin (protobufs)', () => {
const protoFile = `${__dirname}/integration/plugin.proto`;

beforeEach(() => {
pact = makeConsumerPact(
'foo-consumer',
'bar-provider',
FfiSpecificationVersion['SPECIFICATION_VERSION_V3']
);
pact.addPlugin('protobuf', '0.1.14');

const interaction = pact.newInteraction('some description');
const protobufContents = {
'pact:proto': protoFile,
'pact:message-type': 'InitPluginRequest',
'pact:content-type': 'application/protobuf',
implementation: "notEmpty('pact-js-driver')",
version: "matching(semver, '0.0.0')",
};

interaction.uponReceiving('a request to get a protobuf');
interaction.given('protobuf state');
interaction.withRequest('GET', '/protobuf');
interaction.withPluginResponseInteractionContents(
'application/protobuf',
JSON.stringify(protobufContents)
);
interaction.withStatus(200);

port = pact.createMockServer(HOST);
});

afterEach(() => {
pact.cleanupPlugins();
});

it('generates a pact with success', async () => {
const root = await load(protoFile);

// Obtain a message type
const InitPluginRequest = root.lookupType(
'io.pact.plugin.InitPluginRequest'
);

return axios
.request({
baseURL: `http://${HOST}:${port}`,
method: 'GET',
url: '/protobuf',
responseType: 'arraybuffer',
})
.then((res) => {
const message: any = InitPluginRequest.decode(res.data);
expect(message.implementation).to.equal('pact-js-driver');
expect(message.version).to.equal('0.0.0');
})
.then(() => {
expect(pact.mockServerMatchedSuccessfully(port)).to.be.true;
})
.then(() => {
// You don't have to call this, it's just here to check it works
const mismatches = pact.mockServerMismatches(port);
expect(mismatches).to.have.length(0);
})
.then(() => {
pact.writePactFile(path.join(__dirname, '__testoutput__'));
})
.then(() => {
pact.cleanupMockServer(port);
});
const skipPluginTests = process.env['SKIP_PLUGIN_TESTS'] === 'true';
(skipPluginTests ? describe.skip : describe)(
'using a plugin (protobufs)',
() => {
const protoFile = `${__dirname}/integration/plugin.proto`;

beforeEach(() => {
pact = makeConsumerPact(
'foo-consumer',
'bar-provider',
FfiSpecificationVersion['SPECIFICATION_VERSION_V3']
);
pact.addPlugin('protobuf', '0.3.15');

const interaction = pact.newInteraction('some description');
const protobufContents = {
'pact:proto': protoFile,
'pact:message-type': 'InitPluginRequest',
'pact:content-type': 'application/protobuf',
implementation: "notEmpty('pact-js-driver')",
version: "matching(semver, '0.0.0')",
};

interaction.uponReceiving('a request to get a protobuf');
interaction.given('protobuf state');
interaction.withRequest('GET', '/protobuf');
interaction.withPluginResponseInteractionContents(
'application/protobuf',
JSON.stringify(protobufContents)
);
interaction.withStatus(200);

port = pact.createMockServer(HOST);
});

afterEach(() => {
pact.cleanupPlugins();
});

it('generates a pact with success', async () => {
const root = await load(protoFile);

// Obtain a message type
const InitPluginRequest = root.lookupType(
'io.pact.plugin.InitPluginRequest'
);

return axios
.request({
baseURL: `http://${HOST}:${port}`,
method: 'GET',
url: '/protobuf',
responseType: 'arraybuffer',
})
.then((res) => {
const message: any = InitPluginRequest.decode(res.data);
expect(message.implementation).to.equal('pact-js-driver');
expect(message.version).to.equal('0.0.0');
})
.then(() => {
expect(pact.mockServerMatchedSuccessfully(port)).to.be.true;
})
.then(() => {
// You don't have to call this, it's just here to check it works
const mismatches = pact.mockServerMismatches(port);
expect(mismatches).to.have.length(0);
})
.then(() => {
pact.writePactFile(path.join(__dirname, '__testoutput__'));
})
.then(() => {
pact.cleanupMockServer(port);
});
});
});
});

describe('with multipart data', () => {
const form = new FormData();
Expand Down
4 changes: 1 addition & 3 deletions test/integration/grpc/grpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"interactions": [
{
"description": "A request to do a foo",
"key": "539a26be10e0124e",
"pending": false,
"request": {
"body": {
Expand Down Expand Up @@ -47,7 +46,6 @@
"markup": "```protobuf\nmessage Feature {\n string name = 1;\n message .routeguide.Point location = 2;\n}\n```\n",
"markupType": "COMMON_MARK"
},
"key": "d81a62841ce862db",
"pending": false,
"pluginConfiguration": {
"protobuf": {
Expand Down Expand Up @@ -143,7 +141,7 @@
}
},
"name": "protobuf",
"version": "0.1.14"
"version": "0.3.15"
}
]
},
Expand Down
Loading

0 comments on commit 813d9a4

Please sign in to comment.