Skip to content

Commit e50d383

Browse files
committed
feat(e2e): add test for invalid arguments in TestRun
1 parent 0ec1e15 commit e50d383

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: test
5+
namespace: default
6+
data:
7+
test.js: |
8+
import http from 'k6/http';
9+
import { check } from 'k6';
10+
11+
export let options = {
12+
vus: 1,
13+
duration: '50s'
14+
};
15+
16+
export default function () {
17+
const result = http.get('https://quickpizza.grafana.com');
18+
check(result, {
19+
'http response status code is 200': result.status === 200,
20+
});
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- ../../latest/
5+
- configmap.yaml

e2e/invalid-arguments/test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Environment } from 'k6/x/environment';
2+
import { sleep, fail } from 'k6';
3+
4+
export const options = {
5+
setupTimeout: '60s',
6+
};
7+
8+
const PARENT = "./"
9+
10+
const env = new Environment({
11+
name: "invalid-arguments",
12+
implementation: "vcluster",
13+
initFolder: PARENT + "manifests", // initial folder with everything that will be loaded at init
14+
})
15+
16+
export function setup() {
17+
console.log("init returns", env.init());
18+
// it is best to have a bit of delay between creating a CRD and
19+
// a corresponding CR, so as to avoid the "no matches" error
20+
sleep(0.5);
21+
}
22+
23+
// TestRun should enter error stage on invalid .spec.arguments
24+
export default function () {
25+
let err = env.apply(PARENT + "testrun.yaml");
26+
console.log("apply testrun returns", err)
27+
28+
err = env.wait({
29+
kind: "TestRun",
30+
name: "k6-sample", //tr.name(),
31+
namespace: "default", //tr.namespace(),
32+
status_key: "stage",
33+
status_value: "error",
34+
}, {
35+
timeout: "5m",
36+
interval: "1m",
37+
});
38+
39+
if (err != null) {
40+
fail("wait returns" + err);
41+
}
42+
}
43+
44+
export function teardown() {
45+
console.log("delete returns", env.delete());
46+
}

e2e/invalid-arguments/testrun.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
apiVersion: k6.io/v1alpha1
3+
kind: TestRun
4+
metadata:
5+
name: k6-sample
6+
spec:
7+
parallelism: 1
8+
arguments: this argument-is-invalid
9+
script:
10+
configMap:
11+
name: "test"
12+
file: "test.js"

e2e/run-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ tests=(
130130
"init-container-volume"
131131
"multifile"
132132
"error-stage"
133+
"invalid-arguments"
133134
"testrun-simultaneous"
134135
"testrun-watch-namespace"
135136
"testrun-watch-namespaces"

0 commit comments

Comments
 (0)