diff --git a/.github/tests/test_job.yaml b/.github/tests/test_job.yaml new file mode 100644 index 00000000..5fc285b5 --- /dev/null +++ b/.github/tests/test_job.yaml @@ -0,0 +1,59 @@ +--- +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" || exit 1; + echo "done" + - name: 10-generate-preview + image: docker.io/library/nextcloud:latest + command: + - /bin/sh + - -c + - | + set -e + echo "fetch preview:" + OUTPUT=$(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 "${OUTPUT}"; + if ! echo "${OUTPUT}" | grep -q "PNG"; then + echo "PNG was not detected" + exit 1; + fi + 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 85796bbf..3649ec15 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 "--values charts/nextcloud/test-values/s3-as-primary-storage.yaml" + 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..e055edbe 100644 --- a/charts/nextcloud/test-values/imaginary.yaml +++ b/charts/nextcloud/test-values/imaginary.yaml @@ -1,4 +1,10 @@ +fullnameOverride: nextcloud + nextcloud: + host: nextcloud + trustedDomains: + - 'nextcloud.nextcloud.svc.cluster.local' + - 'nextcloud' defaultConfigs: imaginary.config.php: true diff --git a/charts/nextcloud/test-values/s3-as-primary-storage.yaml b/charts/nextcloud/test-values/s3-as-primary-storage.yaml index 6e82f550..8baf27d2 100644 --- a/charts/nextcloud/test-values/s3-as-primary-storage.yaml +++ b/charts/nextcloud/test-values/s3-as-primary-storage.yaml @@ -8,6 +8,9 @@ nginx: nextcloud: host: nextcloud + trustedDomains: + - 'nextcloud.nextcloud.svc.cluster.local' + - 'nextcloud' objectStore: s3: enabled: true