Repository navigation
refactor(e2e): consolidate duplicated test helpers into framework #1480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package framework | ||
|
|
||
| import ( | ||
| "archive/tar" | ||
| "bytes" | ||
| "compress/gzip" | ||
|
|
||
| "github.com/google/go-containerregistry/pkg/name" | ||
| "github.com/google/go-containerregistry/pkg/v1/empty" | ||
| "github.com/google/go-containerregistry/pkg/v1/mutate" | ||
| "github.com/google/go-containerregistry/pkg/v1/remote" | ||
| "github.com/google/go-containerregistry/pkg/v1/static" | ||
| "github.com/google/go-containerregistry/pkg/v1/types" | ||
| "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| // BuildFeatureTarGz returns a gzipped tar holding a single file. | ||
| func BuildFeatureTarGz(filename, content string) []byte { | ||
| var buf bytes.Buffer | ||
| gz := gzip.NewWriter(&buf) | ||
| tw := tar.NewWriter(gz) | ||
|
|
||
| hdr := &tar.Header{ | ||
| Name: filename, | ||
| Mode: 0o644, | ||
| Size: int64(len(content)), | ||
| } | ||
| gomega.Expect(tw.WriteHeader(hdr)).To(gomega.Succeed()) | ||
| _, err := tw.Write([]byte(content)) | ||
| ExpectNoError(err) | ||
| gomega.Expect(tw.Close()).To(gomega.Succeed()) | ||
| gomega.Expect(gz.Close()).To(gomega.Succeed()) | ||
| return buf.Bytes() | ||
| } | ||
|
|
||
| // PushFeatureTag pushes a minimal my-feature@1.0.0 OCI feature to refStr. | ||
| func PushFeatureTag(refStr string) { | ||
| layer := static.NewLayer( | ||
| BuildFeatureTarGz("devcontainer-feature.json", `{"id":"my-feature","version":"1.0.0"}`), | ||
| types.OCILayer, | ||
| ) | ||
|
|
||
| img, err := mutate.AppendLayers(empty.Image, layer) | ||
| ExpectNoError(err) | ||
|
|
||
| ref, err := name.ParseReference(refStr, name.Insecure) | ||
| ExpectNoError(err) | ||
|
|
||
| ExpectNoError(remote.Write(ref, img)) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package framework | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/onsi/ginkgo/v2" | ||
| ) | ||
|
|
||
| // UseFileSecretsBackend forces the file backend so tests do not depend on an OS | ||
| // keyring (unavailable in CI); env is restored on cleanup. | ||
| func UseFileSecretsBackend() { | ||
| for k, v := range map[string]string{ | ||
| "DEVSY_SECRETS_BACKEND": "file", | ||
| "DEVSY_SECRETS_PASSPHRASE": "e2e-passphrase", | ||
| } { | ||
| prev, had := os.LookupEnv(k) | ||
| ExpectNoError(os.Setenv(k, v)) | ||
| ginkgo.DeferCleanup(func() { | ||
| if had { | ||
| _ = os.Setenv(k, prev) | ||
| } else { | ||
| _ = os.Unsetenv(k) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package framework | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/onsi/ginkgo/v2" | ||
| ) | ||
|
|
||
| // SetupDockerWorkspace copies testdataPath to a temp dir and returns it with a | ||
| // docker-provider framework; temp dir and workspace are removed on cleanup. | ||
| func SetupDockerWorkspace(testdataPath, initialDir string) (string, *Framework, error) { | ||
| tempDir, err := CopyToTempDir(testdataPath) | ||
| if err != nil { | ||
| return "", nil, err | ||
| } | ||
|
|
||
| f, err := SetupDockerProvider(initialDir+"/bin", "docker") | ||
| if err != nil { | ||
| return "", nil, err | ||
| } | ||
|
|
||
| ginkgo.DeferCleanup(CleanupTempDir, initialDir, tempDir) | ||
| ginkgo.DeferCleanup(f.DevsyWorkspaceDelete, tempDir) | ||
|
|
||
| return tempDir, f, nil | ||
| } | ||
|
|
||
| // SetupDockerWorkspaceAndUp is SetupDockerWorkspace followed by devsy up. | ||
| func SetupDockerWorkspaceAndUp( | ||
| ctx context.Context, | ||
| testdataPath, initialDir string, | ||
| ) (string, *Framework, error) { | ||
| tempDir, f, err := SetupDockerWorkspace(testdataPath, initialDir) | ||
| if err != nil { | ||
| return "", nil, err | ||
| } | ||
|
|
||
| return tempDir, f, f.DevsyUp(ctx, tempDir) | ||
| } | ||
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 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 file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Restore the working directory when provider setup fails.
CopyToTempDirchanges the process working directory. IfSetupDockerProviderreturns an error, this return skips both cleanup registrations. The test process remains intempDir, which can cause later tests to resolve fixture paths from the wrong directory. RestoreinitialDirand removetempDiron this error path.As per coding guidelines, Go code should focus on “simplicity, reliability, and efficiency.”
🤖 Prompt for AI Agents
Source: Coding guidelines