feat: ensure relative WorkingDir work

Currently the default WorkingDir in test is "/", while in reallife it's
empty.

This change the tests to reflect reel life and fix the case where
First WorkingDir is relative.
This commit is contained in:
Mehdi Abaakouk 2020-05-04 15:47:28 +02:00
parent ae9c9b2813
commit cfc9f39176
2 changed files with 11 additions and 2 deletions

View File

@ -48,7 +48,11 @@ func (w *WorkdirCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile
if filepath.IsAbs(resolvedWorkingDir) {
config.WorkingDir = resolvedWorkingDir
} else {
config.WorkingDir = filepath.Join(config.WorkingDir, resolvedWorkingDir)
if config.WorkingDir != "" {
config.WorkingDir = filepath.Join(config.WorkingDir, resolvedWorkingDir)
} else {
config.WorkingDir = filepath.Join("/", resolvedWorkingDir)
}
}
logrus.Infof("Changed working directory to %s", config.WorkingDir)

View File

@ -35,6 +35,11 @@ var workdirTests = []struct {
expectedPath string
snapshotFiles []string
}{
{
path: "a",
expectedPath: "/a",
snapshotFiles: []string{"/a"},
},
{
path: "/a",
expectedPath: "/a",
@ -92,7 +97,7 @@ func TestWorkdirCommand(t *testing.T) {
}()
cfg := &v1.Config{
WorkingDir: "/",
WorkingDir: "",
Env: []string{
"path=usr/",
"home=/root",