MCPcopy
hub / github.com/containerd/containerd / TestNriEnvironmentInjection

Function TestNriEnvironmentInjection

integration/nri_test.go:189–224  ·  view source on GitHub ↗

Test environment variable injection by NRI plugins.

(t *testing.T)

Source from the content-addressed store, hash-verified

187
188// Test environment variable injection by NRI plugins.
189func TestNriEnvironmentInjection(t *testing.T) {
190 skipNriTestIfNecessary(t)
191
192 t.Log("Test that NRI plugins can inject environment variables into containers.")
193
194 var (
195 out = t.TempDir()
196 tc = &nriTest{
197 t: t,
198 plugins: []*mockPlugin{{}},
199 }
200 injectEnv = func(p *mockPlugin, pod *api.PodSandbox, ctr *api.Container) (*api.ContainerAdjustment, []*api.ContainerUpdate, error) {
201 adjust := &api.ContainerAdjustment{}
202 adjust.AddMount(&api.Mount{
203 Destination: "/out",
204 Source: out,
205 Type: "bind",
206 Options: []string{"bind"},
207 })
208 adjust.AddEnv("TEST_ENV_NAME", "TEST_ENV_VALUE")
209 return adjust, nil, nil
210 }
211 )
212
213 tc.plugins[0].createContainer = injectEnv
214 tc.setup()
215
216 podID := tc.runPod("pod0")
217 tc.startContainer(podID, "ctr0",
218 WithCommand("/bin/sh", "-c", "echo $TEST_ENV_NAME > /out/result; sleep 3600"),
219 )
220
221 chk, err := waitForFileAndRead(filepath.Join(out, "result"), time.Second)
222 require.NoError(t, err, "read result")
223 require.Equal(t, "TEST_ENV_VALUE\n", string(chk), "check result")
224}
225
226// Test annotation injection by NRI plugins.
227func TestNriAnnotationInjection(t *testing.T) {

Callers

nothing calls this directly

Calls 7

skipNriTestIfNecessaryFunction · 0.85
WithCommandFunction · 0.85
waitForFileAndReadFunction · 0.85
LogMethod · 0.80
setupMethod · 0.80
runPodMethod · 0.80
startContainerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…