Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 200ff3a

Browse files
committed
Remove os.Chdir and use binary absolute path
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent fa89d93 commit 200ff3a

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

e2e/commands_test.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,22 @@ func TestDetectApp(t *testing.T) {
154154
),
155155
)
156156
defer dir.Remove()
157-
cwd, err := os.Getwd()
158-
assert.NilError(t, err)
159-
assert.NilError(t, os.Chdir(dir.Path()))
160-
defer func() { assert.NilError(t, os.Chdir(cwd)) }()
161-
icmd.RunCommand(dockerApp, "inspect").Assert(t, icmd.Success)
162-
assert.NilError(t, os.Chdir(dir.Join("helm.dockerapp")))
163-
icmd.RunCommand(dockerApp, "inspect").Assert(t, icmd.Success)
164-
icmd.RunCommand(dockerApp, "inspect", ".").Assert(t, icmd.Success)
165-
assert.NilError(t, os.Chdir(dir.Join("render")))
166-
result := icmd.RunCommand(dockerApp, "inspect")
157+
icmd.RunCmd(icmd.Cmd{
158+
Command: []string{dockerApp, "inspect"},
159+
Dir: dir.Path(),
160+
}).Assert(t, icmd.Success)
161+
icmd.RunCmd(icmd.Cmd{
162+
Command: []string{dockerApp, "inspect"},
163+
Dir: dir.Join("helm.dockerapp"),
164+
}).Assert(t, icmd.Success)
165+
icmd.RunCmd(icmd.Cmd{
166+
Command: []string{dockerApp, "inspect", "."},
167+
Dir: dir.Join("helm.dockerapp"),
168+
}).Assert(t, icmd.Success)
169+
result := icmd.RunCmd(icmd.Cmd{
170+
Command: []string{dockerApp, "inspect"},
171+
Dir: dir.Join("render"),
172+
})
167173
result.Assert(t, icmd.Expected{
168174
ExitCode: 1,
169175
Err: "Error: multiple applications found in current directory, specify the application name on the command line",
@@ -183,15 +189,17 @@ func TestPack(t *testing.T) {
183189
icmd.RunCommand(dockerApp, "render", filepath.Join(tempDir, "test")).Assert(t, icmd.Expected{
184190
Out: "nginx",
185191
})
186-
cwd, err := os.Getwd()
187-
assert.NilError(t, err)
188-
assert.NilError(t, os.Chdir(tempDir))
189-
defer func() { assert.NilError(t, os.Chdir(cwd)) }()
190-
icmd.RunCommand(dockerApp, "helm", "test").Assert(t, icmd.Success)
192+
icmd.RunCmd(icmd.Cmd{
193+
Command: []string{dockerApp, "helm", "test"},
194+
Dir: tempDir,
195+
}).Assert(t, icmd.Success)
191196
_, err = os.Stat("test.chart/Chart.yaml")
192197
assert.NilError(t, err)
193198
assert.NilError(t, os.Mkdir("output", 0755))
194-
icmd.RunCommand(dockerApp, "unpack", "test", "-o", "output").Assert(t, icmd.Success)
199+
icmd.RunCmd(icmd.Cmd{
200+
Command: []string{dockerApp, "unpack", "test", "-o", "output"},
201+
Dir: tempDir,
202+
}).Assert(t, icmd.Success)
195203
_, err = os.Stat("output/test.dockerapp/docker-compose.yml")
196204
assert.NilError(t, err)
197205
}

e2e/main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func TestMain(m *testing.M) {
2828
if dockerApp == "" {
2929
dockerApp = filepath.Join(cwd, "../bin/docker-app")
3030
}
31+
dockerApp, err = filepath.Abs(dockerApp)
32+
if err != nil {
33+
panic(err)
34+
}
3135
cmd := exec.Command(dockerApp, "version")
3236
output, err := cmd.CombinedOutput()
3337
if err != nil {

0 commit comments

Comments
 (0)