Skip to content

Commit 46a2649

Browse files
test overriding of env vars
1 parent 16d0643 commit 46a2649

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

main_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,34 @@ func TestOverrideVersionWithEnvVar(t *testing.T) {
3131
assert.Contains(t, output, "libprotoc 3.6.0")
3232
}
3333

34+
func TestLocalEnvFileOverridesGlobalEnvFile(t *testing.T) {
35+
var homePath = dockerized.GetDockerizedRoot() + "/test/home"
36+
var projectPath = dockerized.GetDockerizedRoot() + "/test/project_override_global"
37+
defer context().
38+
WithHome(homePath).
39+
WithHomeEnvFile("PROTOC_VERSION=3.6.0").
40+
WithDir(projectPath).
41+
WithCwd(projectPath).
42+
WithFile(projectPath+"/dockerized.env", "PROTOC_VERSION=3.8.0").
43+
Restore()
44+
var output = testDockerized(t, []string{"-v", "protoc", "--version"})
45+
assert.Contains(t, output, "libprotoc 3.8.0")
46+
}
47+
48+
func TestRuntimeEnvOverridesLocalEnvFile(t *testing.T) {
49+
var homePath = dockerized.GetDockerizedRoot() + "/test/home"
50+
var projectPath = dockerized.GetDockerizedRoot() + "/test/project_override_global"
51+
defer context().
52+
WithHome(homePath).
53+
WithDir(projectPath).
54+
WithCwd(projectPath).
55+
WithFile(projectPath+"/dockerized.env", "PROTOC_VERSION=3.8.0").
56+
WithEnv("PROTOC_VERSION", "3.16.1").
57+
Restore()
58+
var output = testDockerized(t, []string{"protoc", "--version"})
59+
assert.Contains(t, output, "libprotoc 3.16.1")
60+
}
61+
3462
func TestCustomGlobalComposeFileAdditionalService(t *testing.T) {
3563
homePath := dockerized.GetDockerizedRoot() + "/test/additional_service"
3664

@@ -123,6 +151,14 @@ func (c *Context) WithFile(path string, content string) *Context {
123151
return c
124152
}
125153

154+
func (c *Context) WithDir(path string) *Context {
155+
_ = os.MkdirAll(path, os.ModePerm)
156+
c.after = append(c.after, func() {
157+
_ = os.RemoveAll(path)
158+
})
159+
return c
160+
}
161+
126162
func (c *Context) Execute(callback func()) {
127163
for _, before := range c.before {
128164
before()
@@ -187,6 +223,7 @@ func testDockerized(t *testing.T, args []string) string {
187223
var output = capture(func() {
188224
err, exitCode = RunCli(args)
189225
})
226+
println(output)
190227
assert.Nil(t, err, fmt.Sprintf("error: %s", err))
191228
assert.Equal(t, 0, exitCode)
192229
return output

0 commit comments

Comments
 (0)