Skip to content

Commit

Permalink
Added the option to generate K6 Request tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim committed Sep 18, 2021
1 parent 7b9bec3 commit aa8a167
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 41 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Postman-to-k6

> This is a fork of the original [postman-to-k6](https://github.com/grafana/postman-to-k6) repo, which contains new features & fixes.
> This is a fork of the original [postman-to-k6](https://github.com/grafana/postman-to-k6) repo, which contains [new features & fixes](CHANGELOG.md).
Converts a [Postman collection](https://www.getpostman.com/docs/collections) to a [k6 script](https://docs.k6.io/docs).

Expand All @@ -29,7 +29,13 @@ Converts a [Postman collection](https://www.getpostman.com/docs/collections) to
- [Global Variables](#global-variables)
- [CSV Data File](#csv-data-file)
- [JSON Data File](#json-data-file)
- [K6 Param Options File](#k6-param-options-file)
- [K6 Handle Summary as JSON](#k6-handle-summary-as-json)
- [K6 Request tag](#k6-request-tag)
- [Separate](#separate)
- [Skip Post](#skip-pre)
- [Skip Post](#skip-post)
- [CLI options file](#cli-options-file)
- [Docker Usage](#docker-usage)
- [Examples](#examples)
- [Unsupported Features](#unsupported-features)
Expand Down Expand Up @@ -186,18 +192,18 @@ Generate [K6 request name tags](https://k6.io/docs/using-k6/http-requests/#http-
- `request`: uses the request name as tag (example "Show all accounts")
- `folder-request`: uses Postman folder name and the request name (example: "Accounts - Show all accounts")

| Flag | Verbose | Default |
| ---- | ------------------- | ------- |
| | `--request-tagging` | N/A |
| Flag | Verbose | Default |
| ---- | ---------------------- | ------- |
| | `--k6-request-tagging` | N/A |

Example for `request` strategy
```shell
$ postman-to-k6 collection.json --request-tagging=request -o k6-script.js
$ postman-to-k6 collection.json --k6-request-tagging=request -o k6-script.js
```

Example for `folder-request` strategy
```shell
$ postman-to-k6 collection.json --request-tagging=folder-request -o k6-script.js
$ postman-to-k6 collection.json --k6-request-tagging=folder-request -o k6-script.js
```

### Separate
Expand Down
9 changes: 4 additions & 5 deletions bin/postman-to-k6.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ program
.option('--cli-options-file <path>','postman-to-k6 CLI options file. Useful for CI/CD integrations.')
.option('-c, --csv <path>', 'CSV data file. Used to fill data variables.')
.option('-j, --json <path>', 'JSON data file. Used to fill data variables.')
.option('--k6-params <path>','K6 param options config file. Sets K6 params used during HTTP requests.')
.option('--k6-params <path>', 'K6 param options config file. Sets K6 params used during HTTP requests.')
.option('--k6-handle-summary-json <path>', 'Output the K6 handle summary as a JSON file.')
.option('--k6-request-tagging <value>', 'Apply K6 tags to the requests for reporting.')
.option('--skip-pre', 'Skips pre-request scripts')
.option('--skip-post', 'Skips post-request scripts')
.option('--request-tagging <value>', 'Apply K6 tags to the requests for reporting.')
.option('--oauth1-consumer-key <value>', 'OAuth1 consumer key.')
.option('--oauth1-consumer-secret <value>', 'OAuth1 consumer secret.')
.option('--oauth1-access-token <value>', 'OAuth1 access token.')
Expand All @@ -39,7 +40,6 @@ program
.option('--oauth1-version <value>', 'OAuth1 version.')
.option('--oauth1-realm <value>', 'OAuth1 realm.')
.option('-s, --separate', 'Generate a separate file for each request.')
.option('--k6-handle-summary-json <path>','Output the K6 handle summary as a JSON file.')
.action(run)
.parse(process.argv);

Expand All @@ -48,7 +48,6 @@ async function run(...args) {
console.error('Provide path to Postman collection');
return;
}

let options = args.pop();
const input = args.shift();

Expand Down Expand Up @@ -117,11 +116,11 @@ function translateOptions(options) {
csv: !!options.csv,
json: !!options.json,
k6Params: options.k6Params,
k6RequestTagging: options.k6RequestTagging,
iterations: options.iterations,
id: true,
oauth1: translateOauth1Options(options),
separate: !!options.separate,
requestTagging: options.requestTagging,
skip: {
pre: options.skipPre,
post: options.skipPost,
Expand Down
4 changes: 2 additions & 2 deletions lib/convert/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ async function convertObject(collection, options = {}) {
if (options.oauth1) {
result.setting.oauth1 = options.oauth1;
}
if (options.requestTagging) {
result.setting.requestTagging = options.requestTagging;
if (options.k6RequestTagging) {
result.setting.requestTagging = options.k6RequestTagging;
}
result.setting.separate = options.separate;
if (options.iterations) {
Expand Down
40 changes: 20 additions & 20 deletions test/int/requestTagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@
import test from 'ava';
import convertFile from 'convert/file';

test('request --request-tagging=request', async t => {
test('request --k6-request-tagging=request', async t => {
const options = {
requestTagging: 'request',
k6RequestTagging: 'request',
};
const [main] = await convertFile('test/material/2/request.json', options);
t.snapshot(main);
});

test('request --request-tagging=folder-request', async t => {
test('request --k6-request-tagging=folder-request', async t => {
const options = {
requestTagging: 'folder-request',
k6RequestTagging: 'folder-request',
};
const [main] = await convertFile('test/material/2/request.json', options);
t.snapshot(main);
});

test('request no request-tagging', async t => {
const options = {
requestTagging: '',
k6RequestTagging: '',
};
const [main] = await convertFile('test/material/2/request.json', options);
t.snapshot(main);
});

test('folder request --request-tagging=request', async t => {
test('folder request --k6-request-tagging=request', async t => {
const options = {
requestTagging: 'request',
k6RequestTagging: 'request',
};
const [main] = await convertFile(
'test/material/2/inherit-folder.json',
Expand All @@ -38,9 +38,9 @@ test('folder request --request-tagging=request', async t => {
t.snapshot(main);
});

test('folder request --request-tagging=folder-request', async t => {
test('folder request --k6-request-tagging=folder-request', async t => {
const options = {
requestTagging: 'folder-request',
k6RequestTagging: 'folder-request',
};
const [main] = await convertFile(
'test/material/2/inherit-folder.json',
Expand All @@ -51,7 +51,7 @@ test('folder request --request-tagging=folder-request', async t => {

test('folder request no request-tagging', async t => {
const options = {
requestTagging: '',
k6RequestTagging: '',
};
const [main] = await convertFile(
'test/material/2/inherit-folder.json',
Expand All @@ -60,10 +60,10 @@ test('folder request no request-tagging', async t => {
t.snapshot(main);
});

test('request separate --request-tagging=request', async t => {
test('request separate --k6-request-tagging=request', async t => {
const options = {
separate: true,
requestTagging: 'request',
k6RequestTagging: 'request',
};
const [main, requests] = await convertFile(
'test/material/2/request.json',
Expand All @@ -76,10 +76,10 @@ test('request separate --request-tagging=request', async t => {
t.snapshot(requests);
});

test('request separate --request-tagging=folder-request', async t => {
test('request separate --k6-request-tagging=folder-request', async t => {
const options = {
separate: true,
requestTagging: 'folder-request',
k6RequestTagging: 'folder-request',
};
const [main, requests] = await convertFile(
'test/material/2/request.json',
Expand All @@ -95,7 +95,7 @@ test('request separate --request-tagging=folder-request', async t => {
test('request separate no request-tagging', async t => {
const options = {
separate: true,
requestTagging: '',
k6RequestTagging: '',
};
const [main, requests] = await convertFile(
'test/material/2/request.json',
Expand All @@ -108,10 +108,10 @@ test('request separate no request-tagging', async t => {
t.snapshot(requests);
});

test('folder request separate --request-tagging=request', async t => {
test('folder request separate --k6-request-tagging=request', async t => {
const options = {
separate: true,
requestTagging: 'request',
k6RequestTagging: 'request',
};
const [main, requests] = await convertFile(
'test/material/2/inherit-folder.json',
Expand All @@ -124,10 +124,10 @@ test('folder request separate --request-tagging=request', async t => {
t.snapshot(requests);
});

test('folder request separate --request-tagging=folder-request', async t => {
test('folder request separate --k6-request-tagging=folder-request', async t => {
const options = {
separate: true,
requestTagging: 'folder-request',
k6RequestTagging: 'folder-request',
};
const [main, requests] = await convertFile(
'test/material/2/inherit-folder.json',
Expand All @@ -143,7 +143,7 @@ test('folder request separate --request-tagging=folder-request', async t => {
test('folder request separate no request-tagging', async t => {
const options = {
separate: true,
requestTagging: '',
k6RequestTagging: '',
};
const [main, requests] = await convertFile(
'test/material/2/inherit-folder.json',
Expand Down
16 changes: 8 additions & 8 deletions test/int/snapshots/requestTagging.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The actual snapshot is saved in `requestTagging.js.snap`.

Generated by [AVA](https://ava.li).

## folder request --request-tagging=folder-request
## folder request --k6-request-tagging=folder-request

> Snapshot 1
Expand Down Expand Up @@ -35,7 +35,7 @@ Generated by [AVA](https://ava.li).
}␊
`

## folder request --request-tagging=request
## folder request --k6-request-tagging=request

> Snapshot 1
Expand Down Expand Up @@ -96,7 +96,7 @@ Generated by [AVA](https://ava.li).
}␊
`

## folder request separate --request-tagging=folder-request
## folder request separate --k6-request-tagging=folder-request

> Snapshot 1
Expand All @@ -115,7 +115,7 @@ Generated by [AVA](https://ava.li).
},
}

## folder request separate --request-tagging=request
## folder request separate --k6-request-tagging=request

> Snapshot 1
Expand Down Expand Up @@ -152,7 +152,7 @@ Generated by [AVA](https://ava.li).
},
}

## request --request-tagging=folder-request
## request --k6-request-tagging=folder-request

> Snapshot 1
Expand All @@ -177,7 +177,7 @@ Generated by [AVA](https://ava.li).
}␊
`

## request --request-tagging=request
## request --k6-request-tagging=request

> Snapshot 1
Expand Down Expand Up @@ -226,7 +226,7 @@ Generated by [AVA](https://ava.li).
}␊
`

## request separate --request-tagging=folder-request
## request separate --k6-request-tagging=folder-request

> Snapshot 1
Expand All @@ -240,7 +240,7 @@ Generated by [AVA](https://ava.li).
`,
}

## request separate --request-tagging=request
## request separate --k6-request-tagging=request

> Snapshot 1
Expand Down
Binary file modified test/int/snapshots/requestTagging.js.snap
Binary file not shown.

0 comments on commit aa8a167

Please sign in to comment.