From a2217545494786de90bc821ad9aec59d8c39eae2 Mon Sep 17 00:00:00 2001 From: Michelle Dhanani Date: Wed, 6 Mar 2024 01:41:09 -0500 Subject: [PATCH] add e2e to github workflow + adds e2e make target for running e2es + updates return err to include output for better debugging experience + add workflow for checking e2e on PRs to main Signed-off-by: Michelle Dhanani --- .github/workflows/e2e.yaml | 18 ++++++++++++++++++ Makefile | 4 ++++ e2e/main_test.go | 18 ++++++++++++------ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/e2e.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 00000000..8c719733 --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1,18 @@ +name: e2e + +on: + pull_request: + branches: [main] + +jobs: + e2e: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.22.x" + cache: true + - name: run e2e + run: go test ./e2e -v diff --git a/Makefile b/Makefile index 29e8251b..1e887405 100644 --- a/Makefile +++ b/Makefile @@ -288,3 +288,7 @@ $(ENVTEST): $(LOCALBIN) helmify: $(HELMIFY) ## Download helmify locally if necessary. $(HELMIFY): $(LOCALBIN) @test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@$(HELMIFY_VESRION) + +.PHONY: e2e +e2e: ## Run e2e tests + go test -v ./e2e/... diff --git a/e2e/main_test.go b/e2e/main_test.go index 418c1c65..16ee1dcf 100644 --- a/e2e/main_test.go +++ b/e2e/main_test.go @@ -2,6 +2,7 @@ package e2e import ( "context" + "fmt" "os" "testing" "time" @@ -14,6 +15,8 @@ import ( "sigs.k8s.io/e2e-framework/support/utils" ) +const ErrFormat = "%v: %v\n" + var ( testEnv env.Environment testNamespace string @@ -44,11 +47,12 @@ func TestMain(m *testing.M) { // build and load spin operator image into cluster func(ctx context.Context, _ *envconf.Config) (context.Context, error) { if p := utils.RunCommand(`bash -c "cd .. && IMG=ghcr.io/spinkube/spin-operator:dev make docker-build"`); p.Err() != nil { - return ctx, p.Err() + + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } if p := utils.RunCommand(("k3d image import -c " + cluster.name + " ghcr.io/spinkube/spin-operator:dev")); p.Err() != nil { - return ctx, p.Err() + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } return ctx, nil }, @@ -57,20 +61,22 @@ func TestMain(m *testing.M) { func(ctx context.Context, _ *envconf.Config) (context.Context, error) { // install crds if p := utils.RunCommand(`bash -c "cd .. && make install"`); p.Err() != nil { - return ctx, p.Err() + + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) + } // install cert-manager if p := utils.RunCommand("kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.2/cert-manager.yaml"); p.Err() != nil { - return ctx, p.Err() + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } // wait for cert-manager to be ready if p := utils.RunCommand("kubectl wait --for=condition=Available --timeout=300s deployment/cert-manager-webhook -n cert-manager"); p.Err() != nil { - return ctx, p.Err() + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } if p := utils.RunCommand(`bash -c "cd .. && IMG=ghcr.io/spinkube/spin-operator:dev make deploy"`); p.Err() != nil { - return ctx, p.Err() + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } // wait for the controller deployment to be ready