Skip to content

Commit 67e4035

Browse files
committed
add integration test for minikube rm image command
Signed-off-by: Tharun <[email protected]>
1 parent 77ba3e9 commit 67e4035

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

test/integration/functional_test.go

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func TestFunctional(t *testing.T) {
133133
{"DockerEnv", validateDockerEnv},
134134
{"NodeLabels", validateNodeLabels},
135135
{"LoadImage", validateLoadImage},
136+
{"RemoveImage", validateRemoveImage},
136137
}
137138
for _, tc := range tests {
138139
tc := tc
@@ -219,25 +220,72 @@ func validateLoadImage(ctx context.Context, t *testing.T, profile string) {
219220
}
220221

221222
// make sure the image was correctly loaded
223+
rr, err = inspectImage(ctx, t, profile, newImage)
224+
if err != nil {
225+
t.Fatalf("listing images: %v\n%s", err, rr.Output())
226+
}
227+
if !strings.Contains(rr.Output(), newImage) {
228+
t.Fatalf("expected %s to be loaded into minikube but the image is not there", newImage)
229+
}
230+
231+
}
232+
233+
// validateRemoveImage makes sures that `minikube rm image` works as expected
234+
func validateRemoveImage(ctx context.Context, t *testing.T, profile string) {
235+
if NoneDriver() {
236+
t.Skip("load image not available on none driver")
237+
}
238+
if GithubActionRunner() && runtime.GOOS == "darwin" {
239+
t.Skip("skipping on github actions and darwin, as this test requires a running docker daemon")
240+
}
241+
defer PostMortemLogs(t, profile)
242+
243+
// pull busybox
244+
busyboxImage := "busybox:latest"
245+
rr, err := Run(t, exec.CommandContext(ctx, "docker", "pull", busyboxImage))
246+
if err != nil {
247+
t.Fatalf("failed to setup test (pull image): %v\n%s", err, rr.Output())
248+
}
249+
250+
// try to load the image into minikube
251+
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "image", "load", busyboxImage))
252+
if err != nil {
253+
t.Fatalf("loading image into minikube: %v\n%s", err, rr.Output())
254+
}
255+
256+
// try to remove the image from minikube
257+
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "image", "rm", busyboxImage))
258+
if err != nil {
259+
t.Fatalf("removing image from minikube: %v\n%s", err, rr.Output())
260+
}
261+
// make sure the image was removed
262+
rr, err = inspectImage(ctx, t, profile, busyboxImage)
263+
if err != nil {
264+
t.Fatalf("listing images: %v\n%s", err, rr.Output())
265+
}
266+
if strings.Contains(rr.Output(), busyboxImage) {
267+
t.Fatalf("expected %s to be removed from minikube but the image is there", busyboxImage)
268+
}
269+
270+
}
271+
272+
func inspectImage(ctx context.Context, t *testing.T, profile string, image string) (*RunResult, error) {
222273
var cmd *exec.Cmd
223274
if ContainerRuntime() == "docker" {
224-
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "docker", "image", "inspect", newImage)
275+
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "docker", "image", "inspect", image)
225276
} else if ContainerRuntime() == "containerd" {
226277
// crictl inspecti busybox:test-example
227-
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "sudo", "crictl", "inspecti", newImage)
278+
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "sudo", "crictl", "inspecti", image)
228279
} else {
229280
// crio adds localhost prefix
230281
// crictl inspecti localhost/busybox:test-example
231-
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "sudo", "crictl", "inspecti", "localhost/"+newImage)
282+
cmd = exec.CommandContext(ctx, Target(), "ssh", "-p", profile, "--", "sudo", "crictl", "inspecti", "localhost/"+image)
232283
}
233-
rr, err = Run(t, cmd)
284+
rr, err := Run(t, cmd)
234285
if err != nil {
235-
t.Fatalf("listing images: %v\n%s", err, rr.Output())
286+
return rr, err
236287
}
237-
if !strings.Contains(rr.Output(), newImage) {
238-
t.Fatalf("expected %s to be loaded into minikube but the image is not there", newImage)
239-
}
240-
288+
return rr, nil
241289
}
242290

243291
// check functionality of minikube after evaling docker-env

0 commit comments

Comments
 (0)