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

Method prep

pkg/testutil/nerdtest/command.go:122–197  ·  view source on GitHub ↗

Run does override the generic command run, as we are testing both docker and nerdctl

()

Source from the content-addressed store, hash-verified

120
121// Run does override the generic command run, as we are testing both docker and nerdctl
122func (nc *nerdCommand) prep() {
123 nc.T().Helper()
124
125 // If no DOCKER_CONFIG was explicitly provided, set ourselves inside the current working directory
126 if nc.Env["DOCKER_CONFIG"] == "" {
127 nc.Env["DOCKER_CONFIG"] = nc.GenericCommand.TempDir
128 }
129
130 if customDCConfig := nc.GenericCommand.Config.Read(DockerConfig); customDCConfig != "" {
131 if !nc.hasWrittenDockerConfig {
132 dest := filepath.Join(nc.Env["DOCKER_CONFIG"], "config.json")
133 err := filesystem.WriteFile(dest, []byte(customDCConfig), test.FilePermissionsDefault)
134 assert.NilError(nc.T(), err, "failed to write custom docker config json file for test")
135 nc.hasWrittenDockerConfig = true
136 }
137 }
138
139 // For Docker, honor log level and return
140 if !isTargetNerdish() {
141 // Allow debugging with docker syntax
142 if nc.Config.Read(Debug) != "" {
143 nc.PrependArgs("--log-level=debug")
144 }
145 return
146 }
147
148 // nerd-ish cli get the following additionally.
149
150 // Set the namespace
151 if nc.Config.Read(Namespace) != "" {
152 nc.PrependArgs("--namespace=" + string(nc.Config.Read(Namespace)))
153 }
154
155 if nc.Config.Read(stargz) == enabled {
156 nc.Env["CONTAINERD_SNAPSHOTTER"] = "stargz"
157 }
158
159 if nc.Config.Read(ipfs) == enabled {
160 var ipfsPath string
161 if rootlessutil.IsRootless() {
162 var err error
163 ipfsPath, err = platform.DataHome()
164 ipfsPath = filepath.Join(ipfsPath, "ipfs")
165 assert.NilError(nc.T(), err)
166 } else {
167 ipfsPath = filepath.Join(os.Getenv("HOME"), ".ipfs")
168 }
169
170 nc.Env["IPFS_PATH"] = ipfsPath
171 }
172
173 // If no NERDCTL_TOML was explicitly provided, set it to the private dir
174 if nc.Env["NERDCTL_TOML"] == "" {
175 nc.Env["NERDCTL_TOML"] = filepath.Join(nc.GenericCommand.TempDir, "nerdctl.toml")
176 }
177
178 // If we have custom toml content, write it if it does not exist already
179 if nc.Config.Read(NerdctlToml) != "" {

Callers 2

RunMethod · 0.95
BackgroundMethod · 0.95

Calls 8

WriteFileFunction · 0.92
IsRootlessFunction · 0.92
DataHomeFunction · 0.92
isTargetNerdishFunction · 0.85
HelperMethod · 0.65
TMethod · 0.65
ReadMethod · 0.65
PrependArgsMethod · 0.65

Tested by

no test coverage detected