From e11c6ca54e433319c2f94381652f6e93ba7f6185 Mon Sep 17 00:00:00 2001 From: Matthew Boedicker <24275+mmb@users.noreply.github.com> Date: Tue, 3 Mar 2026 21:50:09 -0800 Subject: [PATCH] Shared integration test setup --- .github/workflows/check.yaml | 11 ++++ .golangci.yaml | 1 + tests/integration/integration_suite_test.go | 50 +++++++++---------- .../kustomize/main/kustomization.yaml | 2 + .../kustomize/peer/tmpbbs.statefulset.yaml | 2 +- tests/integration/peer_test.go | 40 ++------------- 6 files changed, 43 insertions(+), 63 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index a1e391f..3a55fb9 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -79,9 +79,20 @@ jobs: uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc with: registry: true + - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f + with: + driver-opts: network=host + buildkitd-config-inline: | + [registry."kind-registry:5000"] + http = true - uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 with: tags: ${{ steps.kind.outputs.LOCAL_REGISTRY }}/tmpbbs:test + build-args: | + VERSION=test + COMMIT=${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max push: true - uses: actions/checkout@v6 - uses: actions/setup-go@v6 diff --git a/.golangci.yaml b/.golangci.yaml index fc18c01..0931da8 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -164,6 +164,7 @@ linters: - gochecknoglobals - godoclint - gosec + - noctx - paralleltest - path: tests/integration linters: diff --git a/tests/integration/integration_suite_test.go b/tests/integration/integration_suite_test.go index 7957b76..61fd7b3 100644 --- a/tests/integration/integration_suite_test.go +++ b/tests/integration/integration_suite_test.go @@ -3,6 +3,7 @@ package integration_test import ( "fmt" "os/exec" + "path/filepath" "testing" . "github.com/onsi/ginkgo/v2" @@ -11,50 +12,45 @@ import ( "github.com/onsi/gomega/gexec" ) -const ( - mainPort = 7800 - mainOverlay = "kustomize/main" - mainNamespace = "tmpbbs" -) +const mainPort = 7800 -var ( - mainURL = fmt.Sprintf("http://localhost:%d", mainPort) - mainPortForwardSession *gexec.Session -) +var mainURL = fmt.Sprintf("http://localhost:%d", mainPort) var _ = BeforeSuite(func() { - var ( - session *gexec.Session - err error - ) + deployOverlay("main", mainPort) +}) - command := exec.Command("kubectl", "apply", "--kustomize", mainOverlay) - session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter) +func TestIntegration(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Integration Suite") +} + +func deployOverlay(name string, port int) { + path := filepath.Join("kustomize", name) + namespace := "tmpbbs-" + name + + command := exec.Command("kubectl", "apply", "--kustomize", path) + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) Eventually(session).Should(gexec.Exit(0)) DeferCleanup(func() { - deleteCommand := exec.Command("kubectl", "delete", "--kustomize", mainOverlay) + deleteCommand := exec.Command("kubectl", "delete", "--kustomize", path) deleteSession, deleteErr := gexec.Start(deleteCommand, GinkgoWriter, GinkgoWriter) Expect(deleteErr).NotTo(HaveOccurred()) Eventually(deleteSession, "30s").Should(gexec.Exit(0)) }) - command = exec.Command("kubectl", "rollout", "status", "statefulset/tmpbbs", "--namespace", mainNamespace) + command = exec.Command("kubectl", "rollout", "status", "statefulset/tmpbbs", "--namespace", namespace) session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) Eventually(session, "2m30s").Should(gexec.Exit(0)) - command = exec.Command("kubectl", "port-forward", "service/tmpbbs-http", "--namespace", mainNamespace, - fmt.Sprintf("%d:8080", mainPort)) - mainPortForwardSession, err = gexec.Start(command, GinkgoWriter, GinkgoWriter) + command = exec.Command("kubectl", "port-forward", "service/tmpbbs-http", "--namespace", namespace, + fmt.Sprintf("%d:8080", port)) + portForwardSession, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) - Eventually(mainPortForwardSession, "10s").Should(gbytes.Say("Forwarding from")) + Eventually(portForwardSession, "10s").Should(gbytes.Say("Forwarding from")) DeferCleanup(func() { - mainPortForwardSession.Terminate() + portForwardSession.Terminate() }) -}) - -func TestIntegration(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Integration Suite") } diff --git a/tests/integration/kustomize/main/kustomization.yaml b/tests/integration/kustomize/main/kustomization.yaml index 41af948..c2278fa 100644 --- a/tests/integration/kustomize/main/kustomization.yaml +++ b/tests/integration/kustomize/main/kustomization.yaml @@ -4,6 +4,8 @@ images: newName: kind-registry:5000/tmpbbs newTag: test +namespace: tmpbbs-main + patches: - path: tmpbbs.statefulset.yaml diff --git a/tests/integration/kustomize/peer/tmpbbs.statefulset.yaml b/tests/integration/kustomize/peer/tmpbbs.statefulset.yaml index e99a224..b33082c 100644 --- a/tests/integration/kustomize/peer/tmpbbs.statefulset.yaml +++ b/tests/integration/kustomize/peer/tmpbbs.statefulset.yaml @@ -12,4 +12,4 @@ spec: - name: TMPBBS_CONFIG_FILE value: - name: TMPBBS_PULL_PEERS - value: tmpbbs-2.tmpbbs.tmpbbs.svc.cluster.local:8081 + value: tmpbbs-2.tmpbbs.tmpbbs-main.svc.cluster.local:8081 diff --git a/tests/integration/peer_test.go b/tests/integration/peer_test.go index e4880bc..3fa34a0 100644 --- a/tests/integration/peer_test.go +++ b/tests/integration/peer_test.go @@ -5,48 +5,18 @@ import ( "io" "net/http" "net/url" - "os/exec" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/onsi/gomega/gbytes" - "github.com/onsi/gomega/gexec" -) - -const ( - peerPort = 7801 - peerOverlay = "kustomize/peer" - peerNamespace = "tmpbbs-peer" ) var _ = Describe("peer", Ordered, func() { - peerURL := fmt.Sprintf("http://localhost:%d", peerPort) + var tmpbbsURL string BeforeAll(func() { - command := exec.Command("kubectl", "apply", "--kustomize", peerOverlay) - session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) - Expect(err).NotTo(HaveOccurred()) - Eventually(session).Should(gexec.Exit(0)) - DeferCleanup(func() { - deleteCommand := exec.Command("kubectl", "delete", "--kustomize", peerOverlay) - deleteSession, deleteErr := gexec.Start(deleteCommand, GinkgoWriter, GinkgoWriter) - Expect(deleteErr).NotTo(HaveOccurred()) - Eventually(deleteSession, "30s").Should(gexec.Exit(0)) - }) - - command = exec.Command("kubectl", "rollout", "status", "statefulset/tmpbbs", "--namespace", peerNamespace) - session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter) - Expect(err).NotTo(HaveOccurred()) - Eventually(session, "1m").Should(gexec.Exit(0)) - - command = exec.Command("kubectl", "port-forward", "service/tmpbbs-http", "--namespace", peerNamespace, - fmt.Sprintf("%d:8080", peerPort)) - peerPortForwardSession, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) - Expect(err).NotTo(HaveOccurred()) - Eventually(peerPortForwardSession, "10s").Should(gbytes.Say("Forwarding from")) - DeferCleanup(func() { - peerPortForwardSession.Terminate() - }) + port := 7801 + deployOverlay("peer", port) + tmpbbsURL = fmt.Sprintf("http://localhost:%d", port) }) It("pulls a post from main", func() { @@ -59,7 +29,7 @@ var _ = Describe("peer", Ordered, func() { Expect(resp.StatusCode).To(Equal(http.StatusOK)) Eventually(func() string { - peerResp, peerErr := http.Get(peerURL) + peerResp, peerErr := http.Get(tmpbbsURL) Expect(peerErr).NotTo(HaveOccurred()) Expect(peerResp.StatusCode).To(Equal(http.StatusOK)) body, bodyErr := io.ReadAll(peerResp.Body)