added unit tests
This commit is contained in:
parent
0158cbf70c
commit
a014c4a1e8
|
|
@ -29,6 +29,8 @@ import (
|
|||
"github.com/GoogleContainerTools/kaniko/testutil"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
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"
|
||||
)
|
||||
|
||||
|
|
@ -405,3 +407,52 @@ func Test_filesToSave(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestInitializeConfig(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
config v1.Config
|
||||
expected v1.Config
|
||||
shouldErr bool
|
||||
}{
|
||||
{
|
||||
description: "env is empty in the image",
|
||||
config: v1.Config{
|
||||
Image: "test",
|
||||
},
|
||||
expected: v1.Config{
|
||||
Env: []string{
|
||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "env is not empty in the image",
|
||||
config: v1.Config{
|
||||
Env: []string{
|
||||
"PATH=/usr/local/something",
|
||||
},
|
||||
},
|
||||
expected: v1.Config{
|
||||
Env: []string{
|
||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
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 := empty.Image
|
||||
mutate.Config(img, tt.config)
|
||||
actual, err :=initializeConfig(img)
|
||||
testutil.CheckErrorAndDeepEqual(t,tt.shouldErr, err, tt.expected, actual.Config)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue