From c866cad6543087668ccc43927492bcfe0b42593a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Mon, 12 Jun 2023 11:47:35 +0200 Subject: [PATCH] ci: use separate CI jobs for e2e tests --- .github/workflows/tests.yaml | 34 ++++++++++++++++++++++++++++++++++ Makefile | 7 ++++++- test/e2e/gke_cluster_test.go | 14 ++++++-------- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 550a7220..d55530a8 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -156,7 +156,32 @@ jobs: - name: integrations tests pased run: echo all integrations tests passed + setup-e2e-tests: + runs-on: ubuntu-latest + outputs: + test_names: ${{ steps.set_test_names.outputs.test_names }} + steps: + + - uses: actions/checkout@v3 + + - id: set_test_names + name: Set test names + working-directory: test/e2e/ + # grep magic described in https://unix.stackexchange.com/a/13472 + # sed to add the extra $ is because some of our test names overlap. we need it so the -run regex only matches one test + run: | + echo "test_names=$(grep -shoP "(?<=^func )(Test[a-zA-z_0-9]+)(?=\(t \*testing.T\) {)" * | sed -e "s/$/\$/"| jq -R . | jq -cs .)" >> $GITHUB_OUTPUT + + - name: Print test names + run: echo "Test names ${{ steps.set_test_names.outputs.test_names }}" + e2e-tests: + needs: + - setup-e2e-tests + strategy: + fail-fast: false + matrix: + test: ${{ fromJSON(needs.setup-e2e-tests.outputs.test_names) }} environment: gcloud runs-on: ubuntu-latest steps: @@ -189,8 +214,17 @@ jobs: if: steps.detect_if_should_run.outputs.result == 'true' run: make test.e2e env: + TEST_RUN: ${{ matrix.test }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }} GOOGLE_LOCATION: ${{ secrets.GOOGLE_LOCATION }} KONG_LICENSE_DATA: ${{ steps.license.outputs.license }} + + e2e-tests-passed: + needs: e2e-tests + if: always() && !contains(needs.*.result, 'failure') + runs-on: ubuntu-latest + steps: + - name: e2e tests pased + run: echo all e2e tests passed \ No newline at end of file diff --git a/Makefile b/Makefile index dc785617..710d6668 100644 --- a/Makefile +++ b/Makefile @@ -55,4 +55,9 @@ test.integration: .PHONY: test.e2e test.e2e: - @GOFLAGS="-tags=e2e_tests" go test -timeout 45m -race -v ./test/e2e/... + @GOFLAGS="-tags=e2e_tests" go test \ + -timeout 45m \ + -run $(TEST_RUN) \ + -race \ + -v \ + ./test/e2e/... diff --git a/test/e2e/gke_cluster_test.go b/test/e2e/gke_cluster_test.go index e4552c2d..e2252e68 100644 --- a/test/e2e/gke_cluster_test.go +++ b/test/e2e/gke_cluster_test.go @@ -35,14 +35,12 @@ var ( gkeLocation = os.Getenv(gke.GKELocationVar) ) -func TestGKECluster(t *testing.T) { - t.Run("create subnet", func(t *testing.T) { - testGKECluster(t, true) - }) +func TestGKECluster_create_subnet(t *testing.T) { + testGKECluster(t, true) +} - t.Run("use default subnet", func(t *testing.T) { - testGKECluster(t, false) - }) +func TestGKECluster_default_subnet(t *testing.T) { + testGKECluster(t, false) } func testGKECluster(t *testing.T, createSubnet bool) { @@ -64,7 +62,7 @@ func testGKECluster(t *testing.T, createSubnet bool) { t.Logf("configuring the GKE cluster PROJECT=(%s) LOCATION=(%s)", gkeProject, gkeLocation) builder := gke.NewBuilder([]byte(gkeCreds), gkeProject, gkeLocation) builder.WithClusterMinorVersion(1, 23) - builder.WithWaitForTeardown(true) + builder.WithWaitForTeardown(false) builder.WithCreateSubnet(createSubnet) builder.WithLabels(map[string]string{"test-cluster": "true"})