Skip to content

Commit

Permalink
tests: unit tests to check if image exists locally logic before pull
Browse files Browse the repository at this point in the history
  • Loading branch information
renzodavid9 committed Oct 23, 2023
1 parent f66ce11 commit 183fcba
Showing 1 changed file with 73 additions and 7 deletions.
80 changes: 73 additions & 7 deletions pkg/skaffold/actions/docker/exec_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (fd *fakeDockerDaemon) ImageID(ctx context.Context, ref string) (string, er
return img, nil
}

func getActionCfg(aName string, containers []latest.VerifyContainer) latest.Action {
func getActionCfg(aName string, containers []latest.VerifyContainer, useLocalImgs bool) latest.Action {
return latest.Action{
Name: aName,
Config: latest.ActionConfig{
Expand All @@ -61,7 +61,9 @@ func getActionCfg(aName string, containers []latest.VerifyContainer) latest.Acti
},
ExecutionModeConfig: latest.ActionExecutionModeConfig{
VerifyExecutionModeType: latest.VerifyExecutionModeType{
LocalExecutionMode: &latest.LocalVerifier{},
LocalExecutionMode: &latest.LocalVerifier{
UseLocalImages: useLocalImgs,
},
},
},
Containers: containers,
Expand All @@ -82,7 +84,7 @@ func TestExecEnv_PrepareActions(t *testing.T) {
shouldFail: true,
errMsg: "action not-created-action not found for local execution mode",
availableAcsCfgs: []latest.Action{
getActionCfg("action1", []latest.VerifyContainer{}),
getActionCfg("action1", []latest.VerifyContainer{}, false),
},
},
{
Expand All @@ -93,11 +95,11 @@ func TestExecEnv_PrepareActions(t *testing.T) {
getActionCfg("action1", []latest.VerifyContainer{
{Name: "container1", Image: "gcr.io/k8s-skaffold/mock:latest"},
{Name: "container2", Image: "gcr.io/k8s-skaffold/mock:latest"},
}),
}, false),
getActionCfg("action2", []latest.VerifyContainer{
{Name: "container3", Image: "gcr.io/k8s-skaffold/mock:latest"},
{Name: "container4", Image: "gcr.io/k8s-skaffold/mock:latest"},
}),
}, false),
},
},
}
Expand Down Expand Up @@ -154,7 +156,7 @@ func TestExecEnv_PullImages(t *testing.T) {
getActionCfg("action1", []latest.VerifyContainer{
{Name: "container1", Image: "gcr.io/k8s-skaffold/mock1:latest"},
{Name: "container2", Image: "gcr.io/k8s-skaffold/mock2:latest"},
}),
}, true),
},
expectedPulledImgs: []string{"gcr.io/k8s-skaffold/mock1:latest", "gcr.io/k8s-skaffold/mock2:latest"},
},
Expand All @@ -165,7 +167,7 @@ func TestExecEnv_PullImages(t *testing.T) {
getActionCfg("action1", []latest.VerifyContainer{
{Name: "container1", Image: "mock1"},
{Name: "container2", Image: "mock2:latest"},
}),
}, false),
},
expectedPulledImgs: []string{"mock2:latest"},
builtImgs: []graph.Artifact{
Expand All @@ -178,6 +180,70 @@ func TestExecEnv_PullImages(t *testing.T) {
"mock1:latest": "id1234",
},
},
{
description: "prepare action, force check if images exists locally - none of them exists",
actionToExec: "action1",
availableAcsCfgs: []latest.Action{
getActionCfg("action1", []latest.VerifyContainer{
{Name: "container1", Image: "gcr.io/k8s-skaffold/mock1:latest"},
{Name: "container2", Image: "gcr.io/k8s-skaffold/mock2:latest"},
}, true),
},
expectedPulledImgs: []string{"gcr.io/k8s-skaffold/mock1:latest", "gcr.io/k8s-skaffold/mock2:latest"},
},
{
description: "prepare action, force check if images exists locally - both exists",
actionToExec: "action1",
availableAcsCfgs: []latest.Action{
getActionCfg("action1", []latest.VerifyContainer{
{Name: "container1", Image: "gcr.io/k8s-skaffold/mock1:latest"},
{Name: "container2", Image: "gcr.io/k8s-skaffold/mock2:latest"},
}, true),
},
imagesInDaemon: map[string]string{
"gcr.io/k8s-skaffold/mock2:latest": "id1111",
"gcr.io/k8s-skaffold/mock1:latest": "id2222",
},
},
{
description: "prepare action, force check if images exists locally - one exists other not",
actionToExec: "action1",
availableAcsCfgs: []latest.Action{
getActionCfg("action1", []latest.VerifyContainer{
{Name: "container1", Image: "gcr.io/k8s-skaffold/mock1:latest"},
{Name: "container2", Image: "gcr.io/k8s-skaffold/mock2:latest"},
}, true),
},
expectedPulledImgs: []string{
"gcr.io/k8s-skaffold/mock2:latest",
},
imagesInDaemon: map[string]string{
"gcr.io/k8s-skaffold/mock1:latest": "id2222",
},
},
{
description: "prepare action, one built locally and one external",
actionToExec: "action1",
availableAcsCfgs: []latest.Action{
getActionCfg("action1", []latest.VerifyContainer{
{Name: "container1", Image: "gcr.io/k8s-skaffold/mock1:latest"},
{Name: "container2", Image: "mock2"},
}, false),
},
builtImgs: []graph.Artifact{
{
ImageName: "mock2",
Tag: "mock2:latest",
},
},
expectedPulledImgs: []string{
"gcr.io/k8s-skaffold/mock1:latest",
},
imagesInDaemon: map[string]string{
"gcr.io/k8s-skaffold/mock1:latest": "id1111",
"mock2:latest": "id2222",
},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 183fcba

Please sign in to comment.