diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2019-09-23 14:46:07 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-09-23 14:47:30 -0700 |
commit | 112736c579690b4fee61e842a65a62fe29b1acb5 (patch) | |
tree | c4ad0be58a0b3e93a4ed84b43b2cb575f96e227a /test/e2e | |
parent | 03ee55cc62c99c5b8f5d6fb00423a66ef44589e3 (diff) |
Add test that runsc exec inherits the same environment as run.
PiperOrigin-RevId: 270764996
Diffstat (limited to 'test/e2e')
-rw-r--r-- | test/e2e/exec_test.go | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/test/e2e/exec_test.go b/test/e2e/exec_test.go index ce2c4f689..267679268 100644 --- a/test/e2e/exec_test.go +++ b/test/e2e/exec_test.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package image provides end-to-end integration tests for runsc. These tests -// require docker and runsc to be installed on the machine. +// Package integration provides end-to-end integration tests for runsc. These +// tests require docker and runsc to be installed on the machine. // // Each test calls docker commands to start up a container, and tests that it // is behaving properly, with various runsc commands. The container is killed @@ -154,3 +154,26 @@ func TestExecError(t *testing.T) { t.Fatalf("docker exec wrong error, got: %s, want: .*%s.*", err.Error(), want) } } + +// Test that exec inherits environment from run. +func TestExecEnv(t *testing.T) { + if err := dockerutil.Pull("alpine"); err != nil { + t.Fatalf("docker pull failed: %v", err) + } + d := dockerutil.MakeDocker("exec-env-test") + + // Start the container with env FOO=BAR. + if err := d.Run("-e", "FOO=BAR", "alpine", "sleep", "1000"); err != nil { + t.Fatalf("docker run failed: %v", err) + } + defer d.CleanUp() + + // Exec "echo $FOO". + got, err := d.Exec("/bin/sh", "-c", "echo $FOO") + 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) + } +} |