MCPcopy
hub / github.com/containerd/containerd / TestContainerdImage

Function TestContainerdImage

integration/containerd_image_test.go:37–162  ·  view source on GitHub ↗

Test to test the CRI plugin should see image pulled into containerd directly.

(t *testing.T)

Source from the content-addressed store, hash-verified

35
36// Test to test the CRI plugin should see image pulled into containerd directly.
37func TestContainerdImage(t *testing.T) {
38 var testImage = images.Get(images.BusyBox)
39 ctx := context.Background()
40
41 t.Logf("make sure the test image doesn't exist in the cri plugin")
42 i, err := imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
43 require.NoError(t, err)
44 if i != nil {
45 require.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: testImage}))
46 }
47
48 t.Logf("pull the image into containerd")
49 lbs := map[string]string{"foo": "bar", labels.PinnedImageLabelKey: labels.PinnedImageLabelValue}
50 _, err = containerdClient.Pull(ctx, testImage, containerd.WithPullUnpack, containerd.WithPullLabels(lbs))
51 assert.NoError(t, err)
52 defer func() {
53 // Make sure the image is cleaned up in any case.
54 if err := containerdClient.ImageService().Delete(ctx, testImage); err != nil {
55 assert.True(t, errdefs.IsNotFound(err), err)
56 }
57 assert.NoError(t, imageService.RemoveImage(&runtime.ImageSpec{Image: testImage}))
58 }()
59
60 t.Logf("the image should be seen by the cri plugin")
61 var id string
62 checkImage := func() (bool, error) {
63 img, err := imageService.ImageStatus(&runtime.ImageSpec{Image: testImage})
64 if err != nil {
65 return false, err
66 }
67 if img == nil {
68 t.Logf("Image %q not show up in the cri plugin yet", testImage)
69 return false, nil
70 }
71 id = img.Id
72 img, err = imageService.ImageStatus(&runtime.ImageSpec{Image: id})
73 if err != nil {
74 return false, err
75 }
76 if img == nil {
77 // We always generate image id as a reference first, it must
78 // be ready here.
79 return false, errors.New("can't reference image by id")
80 }
81 if len(img.RepoTags) != 1 {
82 // RepoTags must have been populated correctly.
83 return false, fmt.Errorf("unexpected repotags: %+v", img.RepoTags)
84 }
85 if img.RepoTags[0] != testImage {
86 return false, fmt.Errorf("unexpected repotag %q", img.RepoTags[0])
87 }
88 return true, nil
89 }
90 require.NoError(t, Eventually(checkImage, 100*time.Millisecond, 10*time.Second))
91 require.NoError(t, Consistently(checkImage, 100*time.Millisecond, time.Second))
92 defer func() {
93 t.Logf("image should still be seen by id if only tag get deleted")
94 if err := containerdClient.ImageService().Delete(ctx, testImage); err != nil {

Callers

nothing calls this directly

Calls 15

GetFunction · 0.92
EventuallyFunction · 0.85
ConsistentlyFunction · 0.85
ContainerConfigFunction · 0.85
WithCommandFunction · 0.85
PullMethod · 0.65
DeleteMethod · 0.65
ImageServiceMethod · 0.65
GetImageMethod · 0.65
LabelsMethod · 0.65
CreateContainerMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…