Provides a library for generating Postman collections using Jsonnet.
These collections can then be imported into Postman UI, or directly run using the newman
command-line runner.
The purpose is to simplify maintaining tests alongside configuration data, both as Jsonnet.
An example collection is provided within example/main.jsonnet
. For now, this is the best
source of documentation.
You will need:
go-jsonnet
(to render your tests to Postman/Newman JSON)newman
(if you wish to run tests from the command line)postman
(if you wish to import/run your tests in the UI)
Whichever installation method you choose, we assume that you have a project directory, and that
you will install within vendor/postman-jsonnet
.
git clone https://github.com/akamai-contrib/postman-jsonnet vendor/postman-jsonnet
jb install https://github.com/akamai-contrib/postman-jsonnet@main
Specifying the
@main
branch is necessary, this repository has eschewed oppressive terminology ๐ฏ.
You can use the following as a basis:
// Use this to have basic Postman/HTTP test functionality
local test = import 'postman-jsonnet/postman.libsonnet';
// Use the following instead if you wish to have Akamai specific test functionality included
// local test = import 'postman-jsonnet/akamai.libsonnet';
test.suite {
name: "Postman Quickstart",
item: [
test.case {
name: "Simple GET Test",
request: test.GET("https://httpbin.org/anything"),
tests: [
test.assertStatusCodeIsOneOf("It works", [200])
]
}
]
}
Store this in a simple test file with a jsonnet extension, for example: postman-quickstart.jsonnet
.
You will now render the Jsonnet file to a JSON file, and it is good practice to store the output
in a separate folder. This command will store the output in a folder called postman
(-o
),
creating it if required (-c
). It will also add the vendor
folder to the library search path,
without which the import 'postman-jsonnet/postman.libsonnet';
statement will fail.
jsonnet -J vendor -co postman/postman-quickstart.json postman-quickstart.jsonnet
If you have installed newman
, you can run:
newman run postman/postman-quickstart.json
newman
Testing with Jsonnet quickstart
โ Postman Quickstart
GET https://httpbin.org/anything [200 OK, 725B, 649ms]
โ It works
โโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโ
โ โ executed โ failed โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโค
โ iterations โ 1 โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโค
โ requests โ 1 โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโค
โ test-scripts โ 3 โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโค
โ prerequest-scripts โ 2 โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโค
โ assertions โ 1 โ 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโค
โ total run duration: 718ms โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ total data received: 495B (approx) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ average response time: 649ms [min: 649ms, max: 649ms, s.d.: 0ยตs] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Of course, you can also import the generated JSON into Postman.
You will need access to the Internet, specifically to httpbin.org
.
cd vendor/postman-jsonnet
jsonnet -co build/example.json example/main.jsonnet
newman run build/example.json