-
-
Save up1/f9883f53f0123148428ab0cd39654ff6 to your computer and use it in GitHub Desktop.
Workshop K6
This file contains hidden or 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
import http from "k6/http"; | |
import { check } from "k6"; | |
export const options = { | |
stages: [ | |
{ duration: "30s", target: 10 }, | |
{ duration: "3m", target: 10 }, | |
{ duration: "30s", target: 0 }, | |
], | |
tags: { | |
name: "workshop-01", | |
type: "load-test", | |
testid: "workshop-01", | |
}, | |
}; | |
export default function () { | |
// Get all users | |
let res = http.get("TARGET_API); | |
check(res, { | |
"status is 200": (r) => r.status === 200, | |
"body is not empty": (r) => r.body.length > 0, | |
}); | |
// Validate with jsonschema | |
const schema = { | |
type: "object", | |
required: [ | |
"id", | |
"product_name", | |
"product_price", | |
"product_price_thb", | |
"product_price_full_thb", | |
"product_image", | |
"stock", | |
"product_brand", | |
], | |
properties: { | |
id: { type: "number" }, | |
product_name: { type: "string" }, | |
product_price: { type: "number" }, | |
product_price_thb: { type: "number" }, | |
product_price_full_thb: { type: "number" }, | |
product_image: { type: "string" }, | |
stock: { type: "number" }, | |
product_brand: { type: "string" }, | |
}, | |
}; | |
check(res, { | |
"response matches schema": (r) => r.json(schema), | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment