commit
224ac8407c
|
|
@ -124,7 +124,7 @@ func initializeConfig(img partial.WithConfigFile) (*v1.ConfigFile, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if img == empty.Image {
|
if imageConfig.Config.Env == nil {
|
||||||
imageConfig.Config.Env = constants.ScratchEnvVars
|
imageConfig.Config.Env = constants.ScratchEnvVars
|
||||||
}
|
}
|
||||||
return imageConfig, nil
|
return imageConfig, nil
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ import (
|
||||||
"github.com/GoogleContainerTools/kaniko/testutil"
|
"github.com/GoogleContainerTools/kaniko/testutil"
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||||
|
"github.com/google/go-containerregistry/pkg/v1/empty"
|
||||||
|
"github.com/google/go-containerregistry/pkg/v1/mutate"
|
||||||
"github.com/moby/buildkit/frontend/dockerfile/instructions"
|
"github.com/moby/buildkit/frontend/dockerfile/instructions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -405,3 +407,58 @@ func Test_filesToSave(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInitializeConfig(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
description string
|
||||||
|
cfg v1.ConfigFile
|
||||||
|
expected v1.Config
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "env is not set in the image",
|
||||||
|
cfg: v1.ConfigFile{
|
||||||
|
Config: v1.Config{
|
||||||
|
Image: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: v1.Config{
|
||||||
|
Image: "test",
|
||||||
|
Env: []string{
|
||||||
|
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "env is set in the image",
|
||||||
|
cfg: v1.ConfigFile{
|
||||||
|
Config: v1.Config{
|
||||||
|
Env: []string{
|
||||||
|
"PATH=/usr/local/something",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: v1.Config{
|
||||||
|
Env: []string{
|
||||||
|
"PATH=/usr/local/something",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "image is empty",
|
||||||
|
expected: v1.Config{
|
||||||
|
Env: []string{
|
||||||
|
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
img, err := mutate.ConfigFile(empty.Image, &tt.cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("error seen when running test %s", err)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
actual, _ := initializeConfig(img)
|
||||||
|
testutil.CheckDeepEqual(t, tt.expected, actual.Config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue