diff options
author | Ian Lewis <ianlewis@google.com> | 2019-10-07 15:54:13 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-10-07 15:55:39 -0700 |
commit | da9e18f24dfdd776d58e0d5bf6345449af724923 (patch) | |
tree | cf65e9e67fa5d78b52e5d290a9b7dec2f238106a /test/e2e | |
parent | 6a9823794975d2401ae1bda3937a63de959192ab (diff) |
Add tests for $HOME
Adds two tests. One to make sure that $HOME is set when starting a container
via 'docker run' and one to make sure that $HOME is set for each container in a
multi-container sandbox.
Issue #701
PiperOrigin-RevId: 273395763
Diffstat (limited to 'test/e2e')
-rw-r--r-- | test/e2e/exec_test.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/test/e2e/exec_test.go b/test/e2e/exec_test.go index 88d26e865..c962a3159 100644 --- a/test/e2e/exec_test.go +++ b/test/e2e/exec_test.go @@ -208,8 +208,27 @@ func TestExecEnv(t *testing.T) { if err != nil { t.Fatalf("docker exec failed: %v", err) } - if want := "BAR"; !strings.Contains(got, want) { - t.Errorf("wanted exec output to contain %q, got %q", want, got) + if got, want := strings.TrimSpace(got), "BAR"; got != want { + t.Errorf("bad output from 'docker exec'. Got %q; Want %q.", got, want) + } +} + +// TestRunEnvHasHome tests that run always has HOME environment set. +func TestRunEnvHasHome(t *testing.T) { + // Base alpine image does not have any environment variables set. + if err := dockerutil.Pull("alpine"); err != nil { + t.Fatalf("docker pull failed: %v", err) + } + d := dockerutil.MakeDocker("run-env-test") + + // Exec "echo $HOME". The 'bin' user's home dir is '/bin'. + got, err := d.RunFg("--user", "bin", "alpine", "/bin/sh", "-c", "echo $HOME") + if err != nil { + t.Fatalf("docker run failed: %v", err) + } + defer d.CleanUp() + if got, want := strings.TrimSpace(got), "/bin"; got != want { + t.Errorf("bad output from 'docker run'. Got %q; Want %q.", got, want) } } |