From da9e18f24dfdd776d58e0d5bf6345449af724923 Mon Sep 17 00:00:00 2001 From: Ian Lewis Date: Mon, 7 Oct 2019 15:54:13 -0700 Subject: 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 --- test/e2e/exec_test.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'test/e2e') 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) } } -- cgit v1.2.3