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

Function TestEnvAdd

mod/tigron/internal/com/command_test.go:355–389  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

353}
354
355func TestEnvAdd(t *testing.T) {
356 t.Setenv("FOO", "BAR")
357 t.Setenv("BLED", "BLED")
358 t.Setenv("BAZ", "OLD")
359
360 command := &com.Command{
361 Binary: "env",
362 Env: map[string]string{
363 "FOO": "REPLACE",
364 "BAR": "NEW",
365 "BLED": "EXPLICIT",
366 },
367 EnvBlackList: []string{
368 "LS_COLORS",
369 "BLED",
370 },
371 }
372
373 err := command.Run(context.WithValue(context.Background(), com.LoggerKey, t))
374
375 assertive.ErrorIsNil(t, err, "Err")
376
377 res, err := command.Wait()
378
379 assertive.ErrorIsNil(t, err, "Err")
380 assertive.IsEqual(t, res.ExitCode, 0, "ExitCode")
381 // Confirm explicit Env: declaration overrides os.Environ
382 assertive.Contains(t, res.Stdout, "FOO=REPLACE", "Stdout")
383 // Confirm explicit Env: declaration does add a new variable
384 assertive.Contains(t, res.Stdout, "BAR=NEW", "Stdout")
385 // Confirm explicit Env: declaration for unrelated variable does not reset os.Environ
386 assertive.Contains(t, res.Stdout, "BAZ=OLD", "Stdout")
387 // Confirm that blacklist only operates on os.Environ and not on any explicitly added Env: declaration
388 assertive.Contains(t, res.Stdout, "BLED=EXPLICIT", "Stdout")
389}
390
391func TestStdoutStderr(t *testing.T) {
392 t.Parallel()

Callers

nothing calls this directly

Calls 4

RunMethod · 0.95
WaitMethod · 0.95
SetenvMethod · 0.65
BackgroundMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…