From 6cb4f4ad596cbe8a75ccc655296c63d694af0364 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 7 Jun 2024 17:26:39 +0100 Subject: [PATCH 1/5] chore(integration): ensure presence of image --- integration/integration_test.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/integration/integration_test.go b/integration/integration_test.go index f2c55ed8..5f8772dc 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "io" "os" "path/filepath" "runtime" @@ -15,6 +16,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/client" "github.com/docker/docker/pkg/stdcopy" "github.com/stretchr/testify/assert" @@ -82,8 +84,8 @@ func TestIntegration(t *testing.T) { "workspace_owner.name": `testing`, "workspace_owner.oidc_access_token": `^$`, // TODO: test OIDC integration "workspace_owner.session_token": `.+`, - "workspace_owner.ssh_private_key": `^$`, // Depends on coder/coder#13366 - "workspace_owner.ssh_public_key": `^$`, // Depends on coder/coder#13366 + "workspace_owner.ssh_private_key": `(?s)^.+?BEGIN OPENSSH PRIVATE KEY.+?END OPENSSH PRIVATE KEY.+?$`, + "workspace_owner.ssh_public_key": `(?s)^ssh-ed25519.+$`, }, }, } { @@ -148,9 +150,17 @@ func setup(ctx context.Context, t *testing.T) string { require.NoError(t, err, "get abs path of parent") t.Logf("src path is %s\n", srcPath) + // Ensure the image is available locally. + refStr := coderImg + ":" + coderVersion + t.Logf("ensuring image %q", refStr) + resp, err := cli.ImagePull(ctx, refStr, image.PullOptions{}) + require.NoError(t, err) + _, err = io.ReadAll(resp) + require.NoError(t, err) + // Stand up a temporary Coder instance ctr, err := cli.ContainerCreate(ctx, &container.Config{ - Image: coderImg + ":" + coderVersion, + Image: refStr, Env: []string{ "CODER_ACCESS_URL=" + localURL, // Set explicitly to avoid creating try.coder.app URLs. "CODER_IN_MEMORY=true", // We don't necessarily care about real persistence here. From f829eea9d3dd562bbb371cd444069d13e61aa4fa Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 7 Jun 2024 17:28:44 +0100 Subject: [PATCH 2/5] ci: run integration test --- .github/workflows/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a4a6bce..c4dc788d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -81,6 +81,14 @@ jobs: run: | go test -v -cover ./provider/ + - name: Run integration test + timeout-minutes: 10 + env: + CODER_IMAGE: "ghcr.io/coder/coder" + CODER_VERSION: "latest" + run: | + go test -v ./integration + lint: name: Lint runs-on: ubuntu-latest From 772f4c78157179dbb8b4379b4d71783e7aa8de3e Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 7 Jun 2024 17:31:43 +0100 Subject: [PATCH 3/5] move to build stage --- .github/workflows/test.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c4dc788d..1f077ef1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,6 +36,14 @@ jobs: run: | go build -v . + - name: Run integration test + timeout-minutes: 10 + env: + CODER_IMAGE: "ghcr.io/coder/coder" + CODER_VERSION: "latest" + run: | + go test -v ./integration + # run acceptance tests in a matrix with Terraform core versions test: name: Matrix Test @@ -81,14 +89,6 @@ jobs: run: | go test -v -cover ./provider/ - - name: Run integration test - timeout-minutes: 10 - env: - CODER_IMAGE: "ghcr.io/coder/coder" - CODER_VERSION: "latest" - run: | - go test -v ./integration - lint: name: Lint runs-on: ubuntu-latest From a4aae833caf86400750dd0fcd5ae0fd6ba287ab2 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 7 Jun 2024 17:41:37 +0100 Subject: [PATCH 4/5] disable cgo in build --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f077ef1..217c065f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,8 @@ jobs: go mod download - name: Build + env: + CGO_ENABLED: "0" run: | go build -v . From 7a6bb17cc4d9faf2e0b54fd6ded7680a230c2e7a Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 7 Jun 2024 20:27:37 +0100 Subject: [PATCH 5/5] name container properly --- integration/integration_test.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/integration/integration_test.go b/integration/integration_test.go index 5f8772dc..1c2046be 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -46,17 +46,14 @@ func TestIntegration(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutMins)*time.Minute) t.Cleanup(cancel) - // Given: we have an existing Coder deployment running locally - ctrID := setup(ctx, t) - for _, tt := range []struct { // Name of the folder under `integration/` containing a test template - templateName string + name string // map of string to regex to be passed to assertOutput() expectedOutput map[string]string }{ { - templateName: "test-data-source", + name: "test-data-source", expectedOutput: map[string]string{ "provisioner.arch": runtime.GOARCH, "provisioner.id": `[a-zA-Z0-9-]+`, @@ -89,15 +86,17 @@ func TestIntegration(t *testing.T) { }, }, } { - t.Run(tt.templateName, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { + // Given: we have an existing Coder deployment running locally + ctrID := setup(ctx, t, tt.name) // Import named template - _, rc := execContainer(ctx, t, ctrID, fmt.Sprintf(`coder templates push %s --directory /src/integration/%s --var output_path=/tmp/%s.json --yes`, tt.templateName, tt.templateName, tt.templateName)) + _, rc := execContainer(ctx, t, ctrID, fmt.Sprintf(`coder templates push %s --directory /src/integration/%s --var output_path=/tmp/%s.json --yes`, tt.name, tt.name, tt.name)) require.Equal(t, 0, rc) // Create a workspace - _, rc = execContainer(ctx, t, ctrID, fmt.Sprintf(`coder create %s -t %s --yes`, tt.templateName, tt.templateName)) + _, rc = execContainer(ctx, t, ctrID, fmt.Sprintf(`coder create %s -t %s --yes`, tt.name, tt.name)) require.Equal(t, 0, rc) // Fetch the output created by the template - out, rc := execContainer(ctx, t, ctrID, fmt.Sprintf(`cat /tmp/%s.json`, tt.templateName)) + out, rc := execContainer(ctx, t, ctrID, fmt.Sprintf(`cat /tmp/%s.json`, tt.name)) require.Equal(t, 0, rc) actual := make(map[string]string) require.NoError(t, json.NewDecoder(strings.NewReader(out)).Decode(&actual)) @@ -106,7 +105,7 @@ func TestIntegration(t *testing.T) { } } -func setup(ctx context.Context, t *testing.T) string { +func setup(ctx context.Context, t *testing.T, name string) string { var ( // For this test to work, we pass in a custom terraformrc to use // the locally built version of the provider. @@ -173,7 +172,7 @@ func setup(ctx context.Context, t *testing.T) string { tfrcPath + ":/tmp/integration.tfrc", // Custom tfrc from above. srcPath + ":/src", // Bind-mount in the repo with the built binary and templates. }, - }, nil, nil, "") + }, nil, nil, "terraform-provider-coder-integration-"+name) require.NoError(t, err, "create test deployment") t.Logf("created container %s\n", ctr.ID) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy