-
Notifications
You must be signed in to change notification settings - Fork 43
fix: ensure prefixed commands do not clobber legacy default values #190
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
Changes from all commits
43f2ed9
7558d4a
9bb4304
1655b4c
564f863
bdd9d8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import ( | |
"path/filepath" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/coder/envbuilder" | ||
"github.com/coder/envbuilder/devcontainer/features" | ||
|
@@ -44,6 +45,54 @@ const ( | |
testImageUbuntu = "localhost:5000/envbuilder-test-ubuntu:latest" | ||
) | ||
|
||
func TestInitScriptInitCommand(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review: this test ensures that INIT_SCRIPT and INIT_COMMAND are executed as specified. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if this could get done in the previous test without having to create a new one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which previous test? |
||
t.Parallel() | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
|
||
// Init script will hit the below handler to signify INIT_SCRIPT works. | ||
initCalled := make(chan struct{}) | ||
initSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
initCalled <- struct{}{} | ||
w.WriteHeader(http.StatusOK) | ||
})) | ||
|
||
srv := createGitServer(t, gitServerOptions{ | ||
files: map[string]string{ | ||
// Let's say /bin/sh is not available and we can only use /bin/ash | ||
"Dockerfile": fmt.Sprintf("FROM %s\nRUN unlink /bin/sh", testImageAlpine), | ||
}, | ||
}) | ||
_, err := runEnvbuilder(t, options{env: []string{ | ||
envbuilderEnv("GIT_URL", srv.URL), | ||
envbuilderEnv("DOCKERFILE_PATH", "Dockerfile"), | ||
envbuilderEnv("INIT_SCRIPT", fmt.Sprintf(`wget -O - %q`, initSrv.URL)), | ||
envbuilderEnv("INIT_COMMAND", "/bin/ash"), | ||
}}) | ||
require.NoError(t, err) | ||
|
||
select { | ||
case <-initCalled: | ||
case <-ctx.Done(): | ||
} | ||
require.NoError(t, ctx.Err(), "init script did not execute for prefixed env vars") | ||
|
||
_, err = runEnvbuilder(t, options{env: []string{ | ||
envbuilderEnv("GIT_URL", srv.URL), | ||
envbuilderEnv("DOCKERFILE_PATH", "Dockerfile"), | ||
fmt.Sprintf(`INIT_SCRIPT=wget -O - %q`, initSrv.URL), | ||
`INIT_COMMAND=/bin/ash`, | ||
}}) | ||
require.NoError(t, err) | ||
|
||
select { | ||
case <-initCalled: | ||
case <-ctx.Done(): | ||
} | ||
require.NoError(t, ctx.Err(), "init script did not execute for legacy env vars") | ||
} | ||
|
||
func TestForceSafe(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
|
||
"github.com/coder/envbuilder" | ||
"github.com/coder/serpent" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
|
@@ -68,8 +69,8 @@ func TestEnvOptionParsing(t *testing.T) { | |
func TestLegacyEnvVars(t *testing.T) { | ||
legacyEnvs := map[string]string{ | ||
"SETUP_SCRIPT": "./setup-legacy-script.sh", | ||
"INIT_SCRIPT": "sleep infinity", | ||
"INIT_COMMAND": "/bin/sh", | ||
"INIT_SCRIPT": "./init-legacy-script.sh", | ||
"INIT_COMMAND": "/bin/zsh", | ||
"INIT_ARGS": "arg1 arg2", | ||
"CACHE_REPO": "example-cache-repo", | ||
"BASE_IMAGE_CACHE_DIR": "/path/to/base/image/cache", | ||
|
@@ -104,36 +105,36 @@ func TestLegacyEnvVars(t *testing.T) { | |
|
||
o := runCLI() | ||
|
||
require.Equal(t, o.SetupScript, legacyEnvs["SETUP_SCRIPT"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review: mostly just fixing expected/actual ordering |
||
require.Equal(t, o.InitScript, legacyEnvs["INIT_SCRIPT"]) | ||
require.Equal(t, o.InitCommand, legacyEnvs["INIT_COMMAND"]) | ||
require.Equal(t, o.InitArgs, legacyEnvs["INIT_ARGS"]) | ||
require.Equal(t, o.CacheRepo, legacyEnvs["CACHE_REPO"]) | ||
require.Equal(t, o.BaseImageCacheDir, legacyEnvs["BASE_IMAGE_CACHE_DIR"]) | ||
require.Equal(t, o.LayerCacheDir, legacyEnvs["LAYER_CACHE_DIR"]) | ||
require.Equal(t, o.DevcontainerDir, legacyEnvs["DEVCONTAINER_DIR"]) | ||
require.Equal(t, o.DevcontainerJSONPath, legacyEnvs["DEVCONTAINER_JSON_PATH"]) | ||
require.Equal(t, o.DockerfilePath, legacyEnvs["DOCKERFILE_PATH"]) | ||
require.Equal(t, o.BuildContextPath, legacyEnvs["BUILD_CONTEXT_PATH"]) | ||
require.Equal(t, o.CacheTTLDays, int64(7)) | ||
require.Equal(t, o.DockerConfigBase64, legacyEnvs["DOCKER_CONFIG_BASE64"]) | ||
require.Equal(t, o.FallbackImage, legacyEnvs["FALLBACK_IMAGE"]) | ||
require.Equal(t, o.ExitOnBuildFailure, true) | ||
require.Equal(t, o.ForceSafe, true) | ||
require.Equal(t, o.Insecure, true) | ||
require.Equal(t, o.IgnorePaths, []string{"/var/run", "/tmp"}) | ||
require.Equal(t, o.SkipRebuild, true) | ||
require.Equal(t, o.GitURL, legacyEnvs["GIT_URL"]) | ||
require.Equal(t, o.GitCloneDepth, int64(1)) | ||
require.Equal(t, o.GitCloneSingleBranch, true) | ||
require.Equal(t, o.GitUsername, legacyEnvs["GIT_USERNAME"]) | ||
require.Equal(t, o.GitPassword, legacyEnvs["GIT_PASSWORD"]) | ||
require.Equal(t, o.GitSSHPrivateKeyPath, legacyEnvs["GIT_SSH_PRIVATE_KEY_PATH"]) | ||
require.Equal(t, o.GitHTTPProxyURL, legacyEnvs["GIT_HTTP_PROXY_URL"]) | ||
require.Equal(t, o.WorkspaceFolder, legacyEnvs["WORKSPACE_FOLDER"]) | ||
require.Equal(t, o.SSLCertBase64, legacyEnvs["SSL_CERT_BASE64"]) | ||
require.Equal(t, o.ExportEnvFile, legacyEnvs["EXPORT_ENV_FILE"]) | ||
require.Equal(t, o.PostStartScriptPath, legacyEnvs["POST_START_SCRIPT_PATH"]) | ||
assert.Equal(t, legacyEnvs["SETUP_SCRIPT"], o.SetupScript) | ||
assert.Equal(t, legacyEnvs["INIT_SCRIPT"], o.InitScript) | ||
assert.Equal(t, legacyEnvs["INIT_COMMAND"], o.InitCommand) | ||
assert.Equal(t, legacyEnvs["INIT_ARGS"], o.InitArgs) | ||
assert.Equal(t, legacyEnvs["CACHE_REPO"], o.CacheRepo) | ||
assert.Equal(t, legacyEnvs["BASE_IMAGE_CACHE_DIR"], o.BaseImageCacheDir) | ||
assert.Equal(t, legacyEnvs["LAYER_CACHE_DIR"], o.LayerCacheDir) | ||
assert.Equal(t, legacyEnvs["DEVCONTAINER_DIR"], o.DevcontainerDir) | ||
assert.Equal(t, legacyEnvs["DEVCONTAINER_JSON_PATH"], o.DevcontainerJSONPath) | ||
assert.Equal(t, legacyEnvs["DOCKERFILE_PATH"], o.DockerfilePath) | ||
assert.Equal(t, legacyEnvs["BUILD_CONTEXT_PATH"], o.BuildContextPath) | ||
assert.Equal(t, int64(7), o.CacheTTLDays) | ||
assert.Equal(t, legacyEnvs["DOCKER_CONFIG_BASE64"], o.DockerConfigBase64) | ||
assert.Equal(t, legacyEnvs["FALLBACK_IMAGE"], o.FallbackImage) | ||
assert.Equal(t, true, o.ExitOnBuildFailure) | ||
assert.Equal(t, true, o.ForceSafe) | ||
assert.Equal(t, true, o.Insecure) | ||
assert.Equal(t, []string{"/var/run", "/tmp"}, o.IgnorePaths) | ||
assert.Equal(t, true, o.SkipRebuild) | ||
assert.Equal(t, legacyEnvs["GIT_URL"], o.GitURL) | ||
assert.Equal(t, int64(1), o.GitCloneDepth) | ||
assert.Equal(t, true, o.GitCloneSingleBranch) | ||
assert.Equal(t, legacyEnvs["GIT_USERNAME"], o.GitUsername) | ||
assert.Equal(t, legacyEnvs["GIT_PASSWORD"], o.GitPassword) | ||
assert.Equal(t, legacyEnvs["GIT_SSH_PRIVATE_KEY_PATH"], o.GitSSHPrivateKeyPath) | ||
assert.Equal(t, legacyEnvs["GIT_HTTP_PROXY_URL"], o.GitHTTPProxyURL) | ||
assert.Equal(t, legacyEnvs["WORKSPACE_FOLDER"], o.WorkspaceFolder) | ||
assert.Equal(t, legacyEnvs["SSL_CERT_BASE64"], o.SSLCertBase64) | ||
assert.Equal(t, legacyEnvs["EXPORT_ENV_FILE"], o.ExportEnvFile) | ||
assert.Equal(t, legacyEnvs["POST_START_SCRIPT_PATH"], o.PostStartScriptPath) | ||
} | ||
|
||
// UpdateGoldenFiles indicates golden files should be updated. | ||
|
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.
review: moving this right to the top so it's checked first thing