mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-22 10:09:36 +02:00
Change condition for the behavior when --no-push=true without --destinations (#2676)
This commit changes the condition check for the behavior when no-push is set to true while destinations are needed. Prior this change, users would have to set destinations even when noPush option is set to true. More specifically, a workaround for tar files to be generated when --no-push is true and destinations is empty is provided where a dummy destination would be set.
This commit is contained in:
@@ -222,6 +222,68 @@ func TestImageNameDigestFile(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestDoPushWithOpts(t *testing.T) {
|
||||
tarPath := "image.tar"
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
opts config.KanikoOptions
|
||||
expectedErr bool
|
||||
}{
|
||||
{
|
||||
name: "no push with tarPath without destinations",
|
||||
opts: config.KanikoOptions{
|
||||
NoPush: true,
|
||||
TarPath: tarPath,
|
||||
},
|
||||
expectedErr: false,
|
||||
}, {
|
||||
name: "no push with tarPath with destinations",
|
||||
opts: config.KanikoOptions{
|
||||
NoPush: true,
|
||||
TarPath: tarPath,
|
||||
Destinations: []string{"image"},
|
||||
},
|
||||
expectedErr: false,
|
||||
}, {
|
||||
name: "no push with tarPath with destinations empty",
|
||||
opts: config.KanikoOptions{
|
||||
NoPush: true,
|
||||
TarPath: tarPath,
|
||||
Destinations: []string{},
|
||||
},
|
||||
expectedErr: false,
|
||||
}, {
|
||||
name: "tarPath with destinations empty",
|
||||
opts: config.KanikoOptions{
|
||||
NoPush: false,
|
||||
TarPath: tarPath,
|
||||
Destinations: []string{},
|
||||
},
|
||||
expectedErr: true,
|
||||
}} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
image, err := random.Image(1024, 4)
|
||||
if err != nil {
|
||||
t.Fatalf("could not create image: %s", err)
|
||||
}
|
||||
defer os.Remove("image.tar")
|
||||
|
||||
err = DoPush(image, &tc.opts)
|
||||
if err != nil {
|
||||
if !tc.expectedErr {
|
||||
t.Errorf("unexpected error with opts: could not push image: %s", err)
|
||||
}
|
||||
} else {
|
||||
if tc.expectedErr {
|
||||
t.Error("expected error with opts not found")
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageNameTagDigestFile(t *testing.T) {
|
||||
image, err := random.Image(1024, 4)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user