Skip to content

Commit

Permalink
Release.1.6.0 (#1)
Browse files Browse the repository at this point in the history
* Extend support for Postman random functions/dynamic variables (#92)

* Fix for unwanted encoding of Postman variables in query string, but keep support for "space" (#113)

* Exclude disabled headers when converting requests (#103)

* Implement postman replaceIn function

* Extended test for url encode handling

* Extended test for url encoding of space characters

* Extended test to exclude disabled headers when converting requests (#103)

* Extended test to include checks for randomPhoneNumber & isoTimestamp

* Updated GH workflow actions

Co-authored-by: Tim <>
  • Loading branch information
thim81 authored Aug 17, 2021
1 parent 3fffb4c commit 243eea8
Show file tree
Hide file tree
Showing 11 changed files with 926 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore linting for
lib/shim/faker.js
5 changes: 5 additions & 0 deletions .github/workflows/build-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
push:
branches:
- master
- main
pull_request:
branches:
- main

jobs:
build-on-push:
runs-on: ubuntu-latest
Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/build-on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish

- name: Build docker image
run: |
echo '${{ secrets.DOCKERHUB_PASSWORD }}' | \
docker login \
--username ${{ secrets.DOCKERHUB_USERNAME }} \
--password-stdin
export tag=${GITHUB_REF/refs\/tags\/v/}
docker build . -t loadimpact/postman-to-k6:$tag
docker tag \
loadimpact/postman-to-k6:$tag \
loadimpact/postman-to-k6:latest
docker push loadimpact/postman-to-k6:$tag
docker push loadimpact/postman-to-k6:latest
# - name: Build docker image
# run: |
# echo '${{ secrets.DOCKERHUB_PASSWORD }}' | \
# docker login \
# --username ${{ secrets.DOCKERHUB_USERNAME }} \
# --password-stdin
# export tag=${GITHUB_REF/refs\/tags\/v/}
# docker build . -t loadimpact/postman-to-k6:$tag
# docker tag \
# loadimpact/postman-to-k6:$tag \
# loadimpact/postman-to-k6:latest
# docker push loadimpact/postman-to-k6:$tag
# docker push loadimpact/postman-to-k6:latest
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore prettier for
lib/shim/faker.js
88 changes: 88 additions & 0 deletions example/v2/replaceIn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"info": {
"_postman_id": "00ff76ea-1b0e-4ad7-910a-3eb13a7bfa8e",
"name": "replaceIn",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Post with collectionVariable set with replaceIn",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"pm.collectionVariables.set(\"email\", pm.variables.replaceIn(\"{{$randomEmail}}\"));",
"pm.collectionVariables.set(\"name\", pm.variables.replaceIn(\"{{$randomFirstName}}\"));",
"pm.collectionVariables.set(\"phone_number\", pm.variables.replaceIn(\"{{$randomPhoneNumber}}\"));",
"pm.collectionVariables.set(\"id\", pm.variables.replaceIn(\"{{$guid}}\"));"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"const resp = pm.response.json();",
"",
"pm.test(\"Check response consistency\", function () {",
" pm.expect(resp.json.email).to.be.equal(pm.collectionVariables.get(\"email\"));",
" pm.expect(resp.json.name).to.be.equal(pm.collectionVariables.get(\"name\"));",
" pm.expect(resp.json.phone_number).to.be.equal(pm.collectionVariables.get(\"phone_number\"));",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"{{email}}\",\n \"name\": \"{{name}}\",\n \"phone_number\": \"{{phone_number}}\",\n \"id\" : \"{{id}}\"\n}"
},
"url": {
"raw": "httpbin.org/post",
"host": [
"httpbin",
"org"
],
"path": [
"post"
]
}
},
"response": []
}
],
"variable": [
{
"key": "email",
"value": ""
},
{
"key": "name",
"value": ""
},
{
"key": "phone_number",
"value": ""
},
{
"key": "id",
"value": ""
}
]
}
6 changes: 4 additions & 2 deletions lib/generate/Request/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ function dataGraphQL(body, feature) {
}

function headers(headers, feature, result) {
headers.each(({ key, value }) => {
header(key, value, feature, result);
headers.each(({ key, value, disabled }) => {
if (!disabled) {
header(key, value, feature, result);
}
});
}

Expand Down
18 changes: 14 additions & 4 deletions lib/shim/core.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import k6 from 'k6';
import http from 'k6/http';

/* Load dynamic variables */
import { dynamicGenerators, dynamicGeneratorsRegex } from './dynamic.js';

/* Constants */
const undef = void 0; /* eslint-disable-line no-void */

Expand Down Expand Up @@ -161,20 +164,20 @@ const dynamic = {
guid() {
return guid();
},

/* Random integer [0,1000] */
randomInt() {
return Math.floor(Math.random() * 1001);
},

/* Current time as Unix timestamp */
timestamp() {
return Date.now();
},
};

function computeDynamic(name) {
if (dynamic[name]) {
return dynamic[name]();
const functionName = '$' + name;
if (dynamicGenerators[functionName]) {
return dynamicGenerators[functionName].generator();
} else {
throw new Error(`Unsupported dynamic variable: ${name}`);
}
Expand Down Expand Up @@ -537,6 +540,13 @@ const pm = Object.freeze({
requireRequest();
scope.local = scope.local[Write](name, value);
},
replaceIn(template) {
return template.replace(dynamicGeneratorsRegex, function(match) {
// We remove the enclosing {{ }} to extract the generator type like "$randomName"
const generatorType = match.slice(2, -2);
return dynamicGenerators[generatorType].generator();
});
},
}),

collectionVariables: Object.freeze({
Expand Down
Loading

0 comments on commit 243eea8

Please sign in to comment.