From 3613d8326a7917951798a99c6f5f141a913c27c4 Mon Sep 17 00:00:00 2001 From: WrenIX Date: Mon, 4 Nov 2024 19:21:19 +0100 Subject: [PATCH] fix(ci): run test for preview - WIP Signed-off-by: WrenIX --- .github/tests/test_job.yaml | 54 +++++++++++++++++++++ .github/tests/test_upload_job.yaml | 26 ---------- .github/workflows/lint-test.yaml | 22 +++++---- charts/nextcloud/test-values/imaginary.yaml | 5 ++ 4 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 .github/tests/test_job.yaml delete mode 100644 .github/tests/test_upload_job.yaml diff --git a/.github/tests/test_job.yaml b/.github/tests/test_job.yaml new file mode 100644 index 00000000..1cc867d2 --- /dev/null +++ b/.github/tests/test_job.yaml @@ -0,0 +1,54 @@ +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: test-nextcloud + namespace: nextcloud +spec: + template: + metadata: + name: test-nextcloud + spec: + initContainers: + - name: 05-create-nextcloud-file + image: curlimages/curl + command: + - /bin/sh + - -c + - | + set -e + echo "download image:" + curl -s "https://upload.wikimedia.org/wikipedia/commons/d/df/Open_data.png" -o test_upload.png + echo "upload to nextcloud:" + curl \ + -s \ + -w "%{http_code}" \ + -u admin:changeme \ + -T test_upload.png \ + "http://nextcloud.nextcloud.svc.cluster.local:8080/remote.php/dav/files/admin/test_upload.png" + echo "done" + - name: 10-generate-preview + image: docker.io/library/nextcloud:latest + command: + - /bin/sh + - -c + - | + set -e + echo "fetch preview:" + curl \ + -s \ + -w "%{http_code}" \ + -u admin:changeme \ + "http://nextcloud.nextcloud.svc.cluster.local:8080/index.php/core/preview.png?file=test_upload.png&x=128&y=128&mimeFallback=true&a=0" \ + -o - | file - + echo "done" + containers: + - name: final + image: curlimages/curl + command: + - /bin/sh + - -c + - | + set -e + echo "All tests run successfull (initContainer in given order)" + restartPolicy: Never diff --git a/.github/tests/test_upload_job.yaml b/.github/tests/test_upload_job.yaml deleted file mode 100644 index ec9b9a17..00000000 --- a/.github/tests/test_upload_job.yaml +++ /dev/null @@ -1,26 +0,0 @@ ---- -apiVersion: batch/v1 -kind: Job -metadata: - name: create-nextcloud-file - namespace: nextcloud -spec: - template: - metadata: - name: create-nextcloud-file - spec: - containers: - - name: create-nextcloud-file - image: curlimages/curl - command: - - /bin/sh - - -c - - | - echo "testing123" > test_upload.txt && \ - curl \ - -w "%{http_code}" \ - -u admin:changeme \ - -T test_upload.txt \ - "http://nextcloud.nextcloud.svc.cluster.local:8080/remote.php/dav/files/admin/test_upload.txt" && \ - echo -e "\nTried to uploaded a file, test_upload.txt, to Nextcloud." - restartPolicy: Never diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/lint-test.yaml index a5601351..8fd8bd1b 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/lint-test.yaml @@ -87,10 +87,12 @@ jobs: # we need to skip the clean up so we can test adding a file helm_args: | --namespace nextcloud --skip-clean-up --helm-extra-set-args "--set=fullnameOverride=nextcloud --set=nextcloud.objectStore.s3.enabled=true --set=nextcloud.objectStore.s3.accessKey=nextcloud --set=nextcloud.objectStore.s3.secretKey=rootpass123 --set=nextcloud.objectStore.s3.host=minio.nextcloud.svc.cluster.local --set=nextcloud.objectStore.s3.port=9000 --set=nextcloud.objectStore.s3.ssl=false --set=nextcloud.objectStore.s3.bucket=nextcloud --set=nextcloud.objectStore.s3.usePathStyle=true --set=image.flavor=fpm --set=nginx.enabled=true --set=nextcloud.host=nextcloud --set=nextcloud.trustedDomains[0]='*'" + test: true # test the helm chart with imaginary - name: Imaginary Enabled - helm_args: --helm-extra-set-args "--values charts/nextcloud/test-values/imaginary.yaml" + helm_args: --namespace nextcloud --skip-clean-up --helm-extra-set-args "--create-namespace --values charts/nextcloud/test-values/imaginary.yaml" + test: true steps: - name: Checkout @@ -142,18 +144,20 @@ jobs: if: steps.list-changed.outputs.changed == 'true' run: ct install --target-branch ${{ github.event.repository.default_branch }} ${{ matrix.test_cases.helm_args }} - - name: Try adding a file to Nextcloud - if: matrix.test_cases.name == 'S3 Enabled as Primary Storage' + - name: Run test for Nextcloud + if: matrix.test_cases.test # applies a kubernetes job that uploads a file and then checks log of finished pod run: | + EXIT=0 kubectl config set-context --current --namespace=nextcloud && \ - kubectl apply -f ./.github/tests/test_upload_job.yaml --wait=true && \ + kubectl apply -f ./.github/tests/test_job.yaml --wait=true && \ sleep 2 && \ - kubectl wait --for=condition=Complete --timeout=2m job/create-nextcloud-file && \ - echo "Here's the logs from the job:" && \ - kubectl logs --tail=-1 -f -l batch.kubernetes.io/job-name=create-nextcloud-file && \ - echo "Here's the logs from the nextcloud pod:" && \ - kubectl logs -l app.kubernetes.io/name=nextcloud + kubectl wait --for=condition=Complete --timeout=2m job/test-nextcloud || EXIT=1 + echo "Here's the logs from the job:" + kubectl logs --ignore-errors --prefix --tail=-1 --all-containers=true -l batch.kubernetes.io/job-name=test-nextcloud + echo "Here's the logs from the nextcloud pod:" + kubectl logs --ignore-errors --prefix -l app.kubernetes.io/name=nextcloud + exit $EXIT summary: runs-on: ubuntu-latest-low diff --git a/charts/nextcloud/test-values/imaginary.yaml b/charts/nextcloud/test-values/imaginary.yaml index 389a1580..4f3578f5 100644 --- a/charts/nextcloud/test-values/imaginary.yaml +++ b/charts/nextcloud/test-values/imaginary.yaml @@ -1,4 +1,9 @@ +fullnameOverride: nextcloud + nextcloud: + host: nextcloud + trustedDomains: + - '*' defaultConfigs: imaginary.config.php: true