Skip to content

Commit

Permalink
test: refactor kuttl test using env var (#1214)
Browse files Browse the repository at this point in the history
Signed-off-by: realanna <[email protected]>
  • Loading branch information
RealAnna authored Apr 13, 2023
1 parent acf5f91 commit 24b2674
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rules:
key-duplicates: enable
key-ordering: disable
line-length:
max: 150
max: 155
new-line-at-end-of-file: enable
new-lines: enable
octal-values: enable
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $(HELMIFY): $(LOCALBIN)
test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/keptn/helmify/cmd/helmify@b1da2bb756ec4328bac7645da037a6fb4e6f30cf

.PHONY: integration-test #these tests should run on a real cluster!
integration-test:
integration-test: # to run a single test by name use --test eg. --test=expose-keptn-metric
kubectl kuttl test --start-kind=false ./test/integration/ --config=kuttl-test.yaml

.PHONY: integration-test-local #these tests should run on a real cluster!
Expand Down
9 changes: 0 additions & 9 deletions test/integration/expose-keptn-metric/00-assert.yaml

This file was deleted.

11 changes: 11 additions & 0 deletions test/integration/expose-keptn-metric/00-teststep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: kuttl.dev/v1
kind: TestStep
commands: # generating job and metric based on namespace to avoid interference between runs
- script: |
export NAME=$( echo $NAMESPACE | tr -d -)
echo "installing first job"
envsubst < job-no-metric.yaml | kubectl apply -f -
- script: |
export NAME=$( echo $NAMESPACE | tr -d -)
echo "asserting first job"
kubectl wait --for=condition=complete job $NAME-job1 -n $NAMESPACE
9 changes: 0 additions & 9 deletions test/integration/expose-keptn-metric/01-assert.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions test/integration/expose-keptn-metric/01-teststep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kuttl.dev/v1
kind: TestStep
commands:
- script: | # generating job and metric based on namespace to avoid interference between runs
export NAME=$( echo $NAMESPACE | tr -d -)
echo "installing second job"
envsubst < job-existing-metric.yaml | kubectl apply -f -
- script: | # generating job assertion file
export NAME=$( echo $NAMESPACE | tr -d -)
echo "asserting second job"
kubectl wait --for=condition=complete job $NAME-job2 -n $NAMESPACE
4 changes: 0 additions & 4 deletions test/integration/expose-keptn-metric/02-teststep.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: metrics.keptn.sh/v1alpha2
kind: KeptnMetric
metadata:
name: keptnmetric-sample
namespace: keptn-lifecycle-toolkit-system
name: $NAME
namespace: $NAMESPACE
spec:
provider:
name: "provider"
Expand All @@ -12,7 +12,8 @@ spec:
apiVersion: batch/v1
kind: Job
metadata:
name: test2
name: $NAME-job2
namespace: $NAMESPACE
spec:
backoffLimit: 5
template:
Expand All @@ -25,7 +26,8 @@ spec:
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/metrics > ~/out.txt
if grep -Fxq "# HELP keptnmetric_sample keptnmetric-sample" ~/out.txt
echo ~/out.txt
if grep -Fxq "# HELP $NAME $NAME" ~/out.txt
then
exit 0
fi
Expand All @@ -37,8 +39,9 @@ spec:
- /bin/sh
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics/keptn-lifecycle-toolkit-system/keptnmetric-sample > ~/out.txt
if grep -F "keptnmetric-sample" ~/out.txt
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics/$NAMESPACE/$NAME > ~/out.txt
echo ~/out.txt
if grep -F "$NAME" ~/out.txt
then
exit 0
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: batch/v1
kind: Job
metadata:
name: test
name: $NAME-job1
namespace: $NAMESPACE
spec:
backoffLimit: 0
template:
Expand All @@ -14,7 +15,7 @@ spec:
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/metrics > ~/out.txt
if grep -Fxq "# HELP keptnmetric_sample keptnmetric-sample" ~/out.txt
if grep -Fxq "# HELP $NAME $NAME" ~/out.txt
then
exit 1
fi
Expand All @@ -24,8 +25,8 @@ spec:
- /bin/sh
- -ec
- |
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics//keptnmetric-sample > ~/out.txt
if grep -F "keptnmetric-sample" ~/out.txt
curl -s metrics-operator-service.keptn-lifecycle-toolkit-system.svc.cluster.local:9999/api/v1/metrics/$NAMESPACE/$NAME > ~/out.txt
if grep -F "$NAME" ~/out.txt
then
exit 1
fi
Expand Down

0 comments on commit 24b2674

Please sign in to comment.