Add Comprehensive Backend Unit Test Suite with Ginkgo Framework (#460) #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow runs tests to verify all the API Server REST Endpoints | |
| name: Backend Unit Tests | |
| env: | |
| TESTS_DIR: "./components/backend/handlers" | |
| TESTS_LABEL: "unit" | |
| JUNIT_FILENAME: "junit.xml" | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| test_label: | |
| description: "Test label that you want to filter on and run" | |
| default: 'unit' | |
| required: true | |
| type: string | |
| default_namespace: | |
| description: "Default namespace for testing" | |
| default: 'test-namespace' | |
| required: false | |
| type: string | |
| pull_request: | |
| paths: | |
| - '.github/workflows/backend-unit-tests.yml' | |
| - './components/backend/**' | |
| - '!**/*.md' | |
| concurrency: | |
| group: backend-unit-tests-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| backend-unit-test: | |
| runs-on: ubuntu-latest | |
| name: Ambient Code Backend Unit Tests | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Create reports directory | |
| shell: bash | |
| working-directory: ${{ env.TESTS_DIR }} | |
| run: | | |
| mkdir -p reports | |
| - name: Configure Input Variables | |
| shell: bash | |
| id: configure | |
| run: | | |
| TEST_LABEL=${{ env.TESTS_LABEL }} | |
| DEFAULT_NAMESPACE="test-namespace" | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| TEST_LABEL=${{ inputs.test_label }} | |
| DEFAULT_NAMESPACE=${{ inputs.default_namespace }} | |
| fi | |
| { | |
| echo "TEST_LABEL=$TEST_LABEL" | |
| echo "DEFAULT_NAMESPACE=$DEFAULT_NAMESPACE" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Run Tests | |
| id: run-tests | |
| shell: bash | |
| working-directory: ${{ env.TESTS_DIR }} | |
| run: | | |
| go run github.com/onsi/ginkgo/v2/ginkgo -r -v --cover --keep-going --github-output=true --tags=test --label-filter=${{ steps.configure.outputs.TEST_LABEL }} --junit-report=${{ env.JUNIT_FILENAME }} --output-dir=reports -- -testNamespace=${{ steps.configure.outputs.DEFAULT_NAMESPACE }} | |
| continue-on-error: true | |
| - name: Install Junit2Html plugin and generate report | |
| if: (!cancelled()) | |
| shell: bash | |
| run: | | |
| pip install junit2html | |
| junit2html ${{ env.TESTS_DIR }}/reports/${{ env.JUNIT_FILENAME }} ${{ env.TESTS_DIR }}/reports/test-report.html | |
| continue-on-error: true | |
| - name: Configure report name | |
| id: name_gen | |
| shell: bash | |
| run: | | |
| uuid=$(uuidgen) | |
| REPORT_NAME="Backend Unit Tests HTML Report - ${{ github.run_id }}_${{ github.job }}_$uuid" | |
| echo "REPORT_NAME=$REPORT_NAME" >> "$GITHUB_OUTPUT" | |
| - name: Upload HTML Report | |
| id: upload | |
| uses: actions/upload-artifact@v4 | |
| if: (!cancelled()) | |
| with: | |
| name: ${{ steps.name_gen.outputs.REPORT_NAME }} | |
| path: ${{ env.TESTS_DIR }}/reports/test-report.html | |
| retention-days: 7 | |
| continue-on-error: true | |
| - name: Publish Test Summary With HTML Report | |
| id: publish | |
| uses: kubeflow/pipelines/.github/actions/junit-summary@master | |
| if: (!cancelled()) && steps.upload.outcome != 'failure' | |
| with: | |
| xml_files: '${{ env.TESTS_DIR }}/reports' | |
| custom_data: '{\"HTML Report\": \"${{ steps.upload.outputs.artifact-url }}\"}' | |
| continue-on-error: true | |
| - name: Publish Test Summary | |
| id: summary | |
| uses: kubeflow/pipelines/.github/actions/junit-summary@master | |
| if: (!cancelled()) && steps.upload.outcome == 'failure' | |
| with: | |
| xml_files: '${{ env.TESTS_DIR }}/reports' | |
| continue-on-error: true | |
| - name: Mark Workflow failure if test step failed | |
| if: steps.run-tests.outcome != 'success' && !cancelled() | |
| shell: bash | |
| run: exit 1 | |
| - name: Mark Workflow failure if test reporting failed | |
| if: (steps.publish.outcome == 'failure' || steps.summary.outcome == 'failure' || steps.upload.outcome != 'success') && !cancelled() | |
| shell: bash | |
| run: exit 1 |