MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestImageImport

Function TestImageImport

cmd/nerdctl/image/image_import_linux_test.go:71–205  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestImageImport(t *testing.T) {
72 testCase := nerdtest.Setup()
73
74 var stopServer func()
75
76 testCase.SubTests = []*test.Case{
77 {
78 Description: "image import from stdin",
79 Cleanup: func(data test.Data, helpers test.Helpers) {
80 helpers.Anyhow("rmi", "-f", data.Identifier())
81 },
82 Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
83 cmd := helpers.Command("import", "-", data.Identifier())
84 cmd.Feed(bytes.NewReader(minimalRootfsTar(t).Bytes()))
85 return cmd
86 },
87 Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
88 identifier := data.Identifier()
89 return &test.Expected{
90 Output: expect.All(
91 func(stdout string, t tig.T) {
92 imgs := helpers.Capture("images")
93 assert.Assert(t, strings.Contains(imgs, identifier))
94 },
95 ),
96 }
97 },
98 },
99 {
100 Description: "image import from file",
101 Cleanup: func(data test.Data, helpers test.Helpers) {
102 helpers.Anyhow("rmi", "-f", data.Identifier())
103 },
104 Setup: func(data test.Data, helpers test.Helpers) {
105 p := filepath.Join(data.Temp().Path(), "rootfs.tar")
106 assert.NilError(t, os.WriteFile(p, minimalRootfsTar(t).Bytes(), 0644))
107 data.Labels().Set("tar", p)
108 },
109 Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
110 return helpers.Command("import", data.Labels().Get("tar"), data.Identifier())
111 },
112 Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
113 identifier := data.Identifier()
114 return &test.Expected{
115 Output: expect.All(
116 func(stdout string, t tig.T) {
117 imgs := helpers.Capture("images")
118 assert.Assert(t, strings.Contains(imgs, identifier))
119 },
120 ),
121 }
122 },
123 },
124 {
125 Description: "image import with message",
126 Cleanup: func(data test.Data, helpers test.Helpers) {
127 helpers.Anyhow("rmi", "-f", data.Identifier())
128 },

Callers

nothing calls this directly

Calls 15

SetupFunction · 0.92
InspectImageFunction · 0.92
StartHTTPServerFunction · 0.92
minimalRootfsTarFunction · 0.85
AssertMethod · 0.80
WriteFileMethod · 0.80
AnyhowMethod · 0.65
IdentifierMethod · 0.65
CommandMethod · 0.65
FeedMethod · 0.65
CaptureMethod · 0.65
PathMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…