MCPcopy
hub / github.com/moby/moby / TestCreateByImageID

Function TestCreateByImageID

integration/container/create_test.go:73–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestCreateByImageID(t *testing.T) {
74 ctx := setupTest(t)
75 apiClient := testEnv.APIClient()
76
77 img, err := apiClient.ImageInspect(ctx, "busybox")
78 assert.NilError(t, err)
79
80 imgIDWithAlgorithm := img.ID
81 assert.Assert(t, imgIDWithAlgorithm != "")
82
83 imgID, _ := strings.CutPrefix(img.ID, "sha256:")
84 assert.Assert(t, imgID != "")
85
86 imgShortID := stringid.TruncateID(img.ID)
87 assert.Assert(t, imgShortID != "")
88
89 testCases := []struct {
90 doc string
91 image string
92 expectedErrType func(error) bool
93 expectedErr string
94 }{
95 {
96 doc: "image ID with algorithm",
97 image: imgIDWithAlgorithm,
98 },
99 {
100 // test case for https://github.com/moby/moby/issues/20972
101 doc: "image ID without algorithm",
102 image: imgID,
103 },
104 {
105 doc: "image short-ID",
106 image: imgShortID,
107 },
108 {
109 doc: "image with ID and algorithm as tag",
110 image: "busybox:" + imgIDWithAlgorithm,
111 expectedErrType: cerrdefs.IsInvalidArgument,
112 expectedErr: "Error response from daemon: invalid reference format",
113 },
114 {
115 doc: "image with ID as tag",
116 image: "busybox:" + imgID,
117 expectedErrType: cerrdefs.IsNotFound,
118 expectedErr: "Error response from daemon: No such image: busybox:" + imgID,
119 },
120 }
121
122 for _, tc := range testCases {
123 t.Run(tc.doc, func(t *testing.T) {
124 t.Parallel()
125 ctx := testutil.StartSpan(ctx, t)
126 resp, err := apiClient.ContainerCreate(ctx, client.ContainerCreateOptions{
127 Config: &container.Config{Image: tc.image},
128 })
129 if tc.expectedErr != "" {
130 assert.Check(t, is.DeepEqual(resp, client.ContainerCreateResult{}))

Callers

nothing calls this directly

Calls 9

StartSpanFunction · 0.92
APIClientMethod · 0.80
CheckMethod · 0.80
setupTestFunction · 0.70
ImageInspectMethod · 0.65
RunMethod · 0.65
ContainerCreateMethod · 0.65
ContainerRemoveMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…