From f0a2c980b9f1042e1523d876a73f9967098ade25 Mon Sep 17 00:00:00 2001 From: Parham Alvani Date: Mon, 11 Dec 2023 16:53:13 +0000 Subject: [PATCH] Provide e2e testing based on kuttl (#154) * feat: add e2e testing workflow with kuttl --- .github/workflows/e2e.yaml | 29 ++++++++++++++++++ kuttl-test.yaml | 7 +++++ tests/nack.yaml | 7 +++++ tests/nats.yaml | 27 +++++++++++++++++ tests/stream-creation/00-nack.yaml | 11 +++++++ tests/stream-creation/01-stream.yaml | 7 +++++ tests/stream-creation/02-natscli-stream.yaml | 7 +++++ tests/stream-creation/asserted-natscli.yaml | 8 +++++ .../asserted-rides-stream.yaml | 30 +++++++++++++++++++ tests/stream-creation/natscli.yaml | 19 ++++++++++++ tests/stream-creation/rides-stream.yaml | 10 +++++++ 11 files changed, 162 insertions(+) create mode 100644 .github/workflows/e2e.yaml create mode 100644 kuttl-test.yaml create mode 100644 tests/nack.yaml create mode 100644 tests/nats.yaml create mode 100644 tests/stream-creation/00-nack.yaml create mode 100644 tests/stream-creation/01-stream.yaml create mode 100644 tests/stream-creation/02-natscli-stream.yaml create mode 100644 tests/stream-creation/asserted-natscli.yaml create mode 100644 tests/stream-creation/asserted-rides-stream.yaml create mode 100644 tests/stream-creation/natscli.yaml create mode 100644 tests/stream-creation/rides-stream.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 00000000..efd46797 --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1,29 @@ +name: e2e + +on: + push: + branches: + - main + pull_request: + +jobs: + e2e: + name: e2e + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: install kuttl + run: | + curl -L https://github.com/kudobuilder/kuttl/releases/download/v0.15.0/kubectl-kuttl_0.15.0_linux_x86_64 -o /usr/local/bin/kubectl-kuttl + chmod +x /usr/local/bin/kubectl-kuttl + + - name: create kind cluster + uses: helm/kind-action@v1.8.0 + + - name: set up helm + uses: azure/setup-helm@v3 + + - name: run e2e test + run: kubectl kuttl test diff --git a/kuttl-test.yaml b/kuttl-test.yaml new file mode 100644 index 00000000..2a256bf9 --- /dev/null +++ b/kuttl-test.yaml @@ -0,0 +1,7 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestSuite +testDirs: + - tests/ +commands: + - command: kubectl apply -f ./deploy/crds.yml +timeout: 120 diff --git a/tests/nack.yaml b/tests/nack.yaml new file mode 100644 index 00000000..4c3e4a6d --- /dev/null +++ b/tests/nack.yaml @@ -0,0 +1,7 @@ +jetstream: + enabled: true + + nats: + url: nats://nats:4222 + +namespaced: true diff --git a/tests/nats.yaml b/tests/nats.yaml new file mode 100644 index 00000000..311ed523 --- /dev/null +++ b/tests/nats.yaml @@ -0,0 +1,27 @@ +--- +global: + labels: + app: main-jetstream + +natsBox: + enabled: false + +config: + cluster: + enabled: false + + gateway: + enabled: false + + jetstream: + enabled: true + + memoryStore: + enabled: true + maxSize: 256Mi + + memoryStore: + enabled: true + pvc: + enabled: true + size: 256Mi diff --git a/tests/stream-creation/00-nack.yaml b/tests/stream-creation/00-nack.yaml new file mode 100644 index 00000000..1d2ea1fd --- /dev/null +++ b/tests/stream-creation/00-nack.yaml @@ -0,0 +1,11 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +unitTest: false +commands: + - command: helm uninstall --namespace $NAMESPACE nats + ignoreFailure: true + - command: helm uninstall --namespace $NAMESPACE nack + ignoreFailure: true + - command: helm repo add nats https://nats-io.github.io/k8s/helm/charts + - command: helm upgrade --install --wait --namespace $NAMESPACE nats nats/nats -f ../nats.yaml + - command: helm upgrade --install --wait --namespace $NAMESPACE nack nats/nack -f ../nack.yaml diff --git a/tests/stream-creation/01-stream.yaml b/tests/stream-creation/01-stream.yaml new file mode 100644 index 00000000..99903210 --- /dev/null +++ b/tests/stream-creation/01-stream.yaml @@ -0,0 +1,7 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +apply: + - rides-stream.yaml +assert: + - asserted-rides-stream.yaml +unitTest: false diff --git a/tests/stream-creation/02-natscli-stream.yaml b/tests/stream-creation/02-natscli-stream.yaml new file mode 100644 index 00000000..561e9f92 --- /dev/null +++ b/tests/stream-creation/02-natscli-stream.yaml @@ -0,0 +1,7 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +apply: + - natscli.yaml +assert: + - asserted-natscli.yaml +unitTest: false diff --git a/tests/stream-creation/asserted-natscli.yaml b/tests/stream-creation/asserted-natscli.yaml new file mode 100644 index 00000000..02826111 --- /dev/null +++ b/tests/stream-creation/asserted-natscli.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Pod +metadata: + labels: + run: natscli + name: natscli +status: + phase: Succeeded diff --git a/tests/stream-creation/asserted-rides-stream.yaml b/tests/stream-creation/asserted-rides-stream.yaml new file mode 100644 index 00000000..7d948917 --- /dev/null +++ b/tests/stream-creation/asserted-rides-stream.yaml @@ -0,0 +1,30 @@ +apiVersion: jetstream.nats.io/v1beta2 +kind: Stream +metadata: + name: rides +spec: + allowDirect: false + allowRollup: false + compression: "" + creds: "" + denyDelete: false + discard: old + discardPerSubject: false + firstSequence: 0 + maxAge: "" + maxBytes: -1 + maxConsumers: -1 + maxMsgSize: -1 + maxMsgs: -1 + maxMsgsPerSubject: 0 + name: rides + nkey: "" + noAck: false + preventDelete: false + preventUpdate: false + replicas: 1 + retention: limits + servers: [] + storage: memory + subjects: + - rides.> diff --git a/tests/stream-creation/natscli.yaml b/tests/stream-creation/natscli.yaml new file mode 100644 index 00000000..3d66d5fa --- /dev/null +++ b/tests/stream-creation/natscli.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Pod +metadata: + labels: + run: natscli + name: natscli +spec: + restartPolicy: Never + containers: + - image: natsio/nats-box + name: natscli + command: + - nats + args: + - -s + - nats://nats:4222 + - stream + - info + - rides diff --git a/tests/stream-creation/rides-stream.yaml b/tests/stream-creation/rides-stream.yaml new file mode 100644 index 00000000..6bea5dc7 --- /dev/null +++ b/tests/stream-creation/rides-stream.yaml @@ -0,0 +1,10 @@ +apiVersion: jetstream.nats.io/v1beta2 +kind: Stream +metadata: + name: rides +spec: + name: rides + subjects: + - "rides.>" + storage: memory + replicas: 1