-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hassy/feat/templates
- Loading branch information
Showing
9 changed files
with
244 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use strict'; | ||
|
||
import test from 'ava'; | ||
import createDebug from 'debug'; | ||
const debug = createDebug('expect-plugin:test'); | ||
import EventEmitter from 'events'; | ||
|
||
const shelljs = require('shelljs'); | ||
const path = require('path'); | ||
|
||
// | ||
// We only need this when running unit tests. When the plugin actually runs inside | ||
// a recent version of Artillery, the appropriate object is already set up. | ||
// | ||
global.artillery = { | ||
util: { | ||
template: require('artillery/util').template | ||
} | ||
}; | ||
|
||
test('Basic interface checks', async t => { | ||
const script = { | ||
config: {}, | ||
scenarios: [] | ||
}; | ||
|
||
const ExpectationsPlugin = require('../index'); | ||
const events = new EventEmitter(); | ||
const plugin = new ExpectationsPlugin.Plugin(script, events); | ||
|
||
t.true(typeof ExpectationsPlugin.Plugin === 'function'); | ||
t.true(typeof plugin === 'object'); | ||
|
||
t.pass(); | ||
}); | ||
|
||
test('Expectation: statusCode', async (t) => { | ||
const expectations = require('../lib/expectations'); | ||
|
||
const data = [ | ||
// expectation - value received - user context - expected result | ||
[ '{{ expectedStatus }}', 200, { vars: { expectedStatus: 200 }}, true ], | ||
[ 200, 200, { vars: {}}, true ], | ||
[ '200', 200, { vars: {}}, true ], | ||
[ 200, '200', { vars: {}}, true ], | ||
[ '200', '200', { vars: {}}, true ], | ||
|
||
[ '{{ expectedStatus }}', 200, { vars: { expectedStatus: 202 }}, false ], | ||
[ '{{ expectedStatus }}', '200', { vars: {}}, false ], | ||
[ 301, '200', { vars: {}}, false ], | ||
]; | ||
|
||
data.forEach((e) => { | ||
const result = expectations.statusCode( | ||
{ statusCode: e[0] }, // expectation | ||
{}, // body | ||
{}, // req | ||
{ statusCode: e[1] }, // res | ||
e[2] // userContext | ||
); | ||
|
||
t.true(result.ok === e[3]); | ||
}); | ||
}); | ||
|
||
test('Integration with Artillery', async (t) => { | ||
const output = shelljs.exec( | ||
`${__dirname}/../node_modules/.bin/artillery run --quiet ${__dirname}/pets-test.yaml`, | ||
{ | ||
env: { | ||
ARTILLERY_PLUGIN_PATH: path.resolve(__dirname, '..', '..'), | ||
PATH: process.env.PATH | ||
}, | ||
silent: true | ||
}).stdout; | ||
|
||
t.true(output.indexOf('ok contentType json') > -1); | ||
t.true(output.indexOf('ok statusCode 404') > -1); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/artillery-plugin-expect/test/mock-pets-server.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
- request: | ||
uri: /pets | ||
method: POST | ||
body: "*" | ||
response: | ||
code: 202 | ||
body: '{"success:"true"}' | ||
headers: | ||
content-type: application/json | ||
- request: | ||
uri: /pets | ||
method: GET | ||
response: | ||
code: 200 | ||
body: '{"result": [{"name":"Tiki", "species":"pony"}]}' | ||
headers: | ||
content-type: application/json | ||
- request: | ||
uri: /pets/1 | ||
method: GET | ||
response: | ||
code: 200 | ||
body: '{"result": [{"name": "Luna", "species": "dog"}]}' | ||
headers: | ||
content-type: application/json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
config: | ||
target: http://localhost:9090 | ||
phases: | ||
- duration: 1 | ||
arrivalCount: 1 | ||
plugins: | ||
expect: {} | ||
payload: | ||
- path: "./urls.csv" | ||
fields: | ||
- url | ||
- statusCode | ||
scenarios: | ||
- flow: | ||
- get: | ||
url: "/pets" | ||
expect: | ||
- contentType: json | ||
- statusCode: 200 | ||
- hasProperty: result | ||
- post: | ||
url: "/pets" | ||
json: | ||
name: Tiki | ||
species: pony | ||
expect: | ||
statusCode: 202 | ||
- get: | ||
url: "/pets/1" | ||
capture: | ||
- json: "$.result.0.name" | ||
as: "name" | ||
expect: | ||
statusCode: 200 | ||
contentType: json | ||
equals: | ||
- "{{ name }}" | ||
- "Luna" | ||
- get: | ||
url: "/pets/2" | ||
expect: | ||
statusCode: 404 | ||
- get: | ||
name: "CSV-driven expectation" | ||
url: "{{ url }}" | ||
expect: | ||
statusCode: "{{ statusCode }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
typeset -r DIR=$(cd "$(dirname "$0")" && pwd) | ||
|
||
docker run --rm -p 9090:9090 -v "$DIR":/data quii/mockingjay-server:1.10.7 --config /data/mock-pets-server.yaml & | ||
docker_pid=$! | ||
docker_status=$? | ||
|
||
if [[ $docker_status -ne 0 ]] ; then | ||
echo "Could not start mock server" | ||
exit 1 | ||
fi | ||
|
||
sleep 5 | ||
|
||
test_status=$("$DIR"/../node_modules/.bin/ava $DIR/index.js) | ||
|
||
kill $docker_pid | ||
sleep 5 | ||
|
||
exit $test_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/pets,200 | ||
/pets/1,200 | ||
/pets/100,404 |