-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[test] Ensure image builds preserve environment variables #5609
Closed
Closed
Changes from 1 commit
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 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 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,72 @@ | ||
// Copyright (c) 2021 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package workspace_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
csapi "github.com/gitpod-io/gitpod/content-service/api" | ||
imgapi "github.com/gitpod-io/gitpod/image-builder/api" | ||
"github.com/gitpod-io/gitpod/test/pkg/integration" | ||
agent "github.com/gitpod-io/gitpod/test/tests/workspace/workspace_agent/api" | ||
"github.com/gitpod-io/gitpod/ws-manager/api" | ||
) | ||
|
||
func TestImageBuildPreservesEnvVarMk3(t *testing.T) { | ||
it, ctx := integration.NewTest(t, 5*time.Minute) | ||
defer it.Done() | ||
|
||
res := integration.LaunchWorkspaceDirectly(it, integration.WithWorkspaceImageRequest(&imgapi.ResolveWorkspaceImageRequest{ | ||
Source: &imgapi.BuildSource{ | ||
From: &imgapi.BuildSource_File{ | ||
File: &imgapi.BuildSourceDockerfile{ | ||
DockerfileVersion: "some-version", | ||
DockerfilePath: ".gitpod.Dockerfile", | ||
ContextPath: ".", | ||
Source: &csapi.WorkspaceInitializer{ | ||
Spec: &csapi.WorkspaceInitializer_Git{ | ||
Git: &csapi.GitInitializer{ | ||
RemoteUri: "https://github.com/gitpod-io/gitpod-test-repo.git", | ||
TargetMode: csapi.CloneTargetMode_REMOTE_BRANCH, | ||
// this branch has a docker file that adds 'MY_TEST_ENV_VAR=asd' as env var (ref: https://github.com/gitpod-io/gitpod-test-repo/blob/integration-test/imgbldr/env-is-persisted/.gitpod.Dockerfile#L3) | ||
CloneTaget: "integration-test/imgbldr/env-is-persisted", | ||
Config: &csapi.GitConfig{ | ||
Authentication: csapi.GitAuthMethod_NO_AUTH, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}), integration.WithImageBuilderOpts(integration.SelectImageBuilderMK3)) | ||
defer it.API().WorkspaceManager().StopWorkspace(ctx, &api.StopWorkspaceRequest{ | ||
Id: res.Req.Id, | ||
}) | ||
|
||
rsa, err := it.Instrument(integration.ComponentWorkspace, "workspace", integration.WithInstanceID(res.Req.Id)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer rsa.Close() | ||
|
||
var resp agent.ExecResponse | ||
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{ | ||
Dir: "/workspace", | ||
Command: "bash", | ||
Args: []string{"-c", "echo $MY_TEST_ENV_VAR"}, | ||
}, &resp) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if resp.ExitCode != 0 { | ||
t.Fatalf("got non-zero exit code: %d", resp.ExitCode) | ||
} | ||
if strings.TrimSpace(resp.Stdout) == "" { | ||
t.Fatalf("env var MY_TEST_ENV_VAR is not preserved!") | ||
} | ||
} |
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.
Relying on external, pre-existing fixtures is bound to break. I'd strongly vote for trying to keep these tests self-contained.
We have a content initializer which can download files from a URL. We could use GCP storage to upload the file, produce a pre-signed URL and use that to init the workspace content. Alternatively we should use GitHub API/git to set up the repo before we use it.
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.
Had the same line of thought, but ended it with "file download is equivalent to git clone". The idea with uploading the content upfront is nice, but then we should use sth that is available to all Gitpod installations (abuse content-service?). Also, we kind of break abstractions because we make assumptions about the internal structure of a workspace backup.
Alternatively we could have a variant of the
FileDownloadInitializer
/a newDirecContentInitializer
which allows to pass bytes of a.tar.gz
directly into the initializer spec. This would be awesome for testing. WDYT? @csweichelThere 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.
I added
FilesInitializer
to see how it turns out - and it makes testing much more wholesome. 🤗No hard feelings about names or impl but I like the idea.
Continuing on this: To even more encapsulate theses tests from GitHub especially we could have an CreateWorkspace API that takes an already parsed context (for testing only?). Context parsing itself should be handled by unit tests, so we don't loose anything by taking it out of the loop. Plus we achieve "full GitHub independence". 🙂
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.
Thinking a bit more about it that does not make sense: We still rely on external services after context parsing (config deduction). Moving further down the chain calling
WorkspaceStarter
directly would be nice - and would eliminate the need for the "to-image-build-or-not" in the integration test suite. 😬