Test environment variable injection by NRI plugins.
(t *testing.T)
| 187 | |
| 188 | // Test environment variable injection by NRI plugins. |
| 189 | func 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. |
| 227 | func TestNriAnnotationInjection(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…