Skip to content

Commit

Permalink
Small changes to the templates
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel González Lopes <[email protected]>
  • Loading branch information
dgzlopes committed Dec 27, 2024
1 parent c3f84ba commit fea3e7f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestNewScriptCmd(t *testing.T) {

jsData := string(data)
assert.Contains(t, jsData, "export const options = {")
assert.Contains(t, jsData, "export default function () {")
assert.Contains(t, jsData, "export default function() {")
})
}
}
Expand Down Expand Up @@ -91,5 +91,5 @@ func TestNewScriptCmd_FileExists_Overwrite(t *testing.T) {
require.NoError(t, err)

assert.Contains(t, string(data), "export const options = {")
assert.Contains(t, string(data), "export default function () {")
assert.Contains(t, string(data), "export default function() {")
}
15 changes: 13 additions & 2 deletions cmd/newtemplates/browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { browser } from "k6/browser";
import { check } from "k6";
import http from "k6/http";
import { sleep, check } from 'k6';

const BASE_URL = __ENV.BASE_URL || "https://quickpizza.grafana.com";

Expand All @@ -21,7 +22,16 @@ export const options = {
}, {{ end }}
};

export default async function () {
export function setup() {
let res = http.get(BASE_URL);
if (res.status !== 200) {
throw new Error(
`Got unexpected status code ${res.status} when trying to setup. Exiting.`
);
}
}

export default async function() {
let checkData;
const page = await browser.newPage();
try {
Expand All @@ -40,4 +50,5 @@ export default async function () {
} finally {
await page.close();
}
sleep(1);
}
7 changes: 4 additions & 3 deletions cmd/newtemplates/minimal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import http from 'k6/http';
import { sleep } from 'k6';
import { sleep, check } from 'k6';

export const options = {
vus: 10,
Expand All @@ -11,7 +11,8 @@ export const options = {
}, {{ end }}
};

export default function () {
http.get('https://quickpizza.grafana.com');
export default function() {
let res = http.get('https://quickpizza.grafana.com');
check(res, { "status is 200": (res) => res.status === 200 });
sleep(1);
}
22 changes: 19 additions & 3 deletions cmd/newtemplates/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@ import { check, sleep } from "k6";
const BASE_URL = __ENV.BASE_URL || 'https://quickpizza.grafana.com';

export const options = {
vus: 5,
duration: '10s',{{ if .EnableCloud }}
vus: 10,
stages: [
{ duration: "10s", target: 5 },
{ duration: "20s", target: 10 },
{ duration: "1s", target: 0 },
], thresholds: {
http_req_failed: ["rate<0.01"],
http_req_duration: ["p(95)<500", "p(99)<1000"],
},{{ if .EnableCloud }}
cloud: { {{ if .ProjectID }}
projectID: {{ .ProjectID }}, {{ else }}
// projectID: 12345, // Replace this with your own projectID {{ end }}
name: "{{ .ScriptName }}",
}, {{ end }}
};

export default function () {
export function setup() {
let res = http.get(BASE_URL);
if (res.status !== 200) {
throw new Error(
`Got unexpected status code ${res.status} when trying to setup. Exiting.`
);
}
}

export default function() {
let restrictions = {
maxCaloriesPerSlice: 500,
mustBeVegetarian: false,
Expand Down

0 comments on commit fea3e7f

Please sign in to comment.