Browse Source

Port environment test
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby 11 years ago
parent
commit
47510bd6eb
2 changed files with 45 additions and 54 deletions
  1. 45 0
      integration-cli/docker_cli_run_test.go
  2. 0 54
      integration/container_test.go

+ 45 - 0
integration-cli/docker_cli_run_test.go

@@ -2,8 +2,10 @@ package main
 
 import (
 	"fmt"
+	"os"
 	"os/exec"
 	"regexp"
+	"sort"
 	"strings"
 	"sync"
 	"testing"
@@ -515,3 +517,46 @@ func TestRunTwoConcurrentContainers(t *testing.T) {
 
 	logDone("run - two concurrent containers")
 }
+
+func TestEnvironment(t *testing.T) {
+	cmd := exec.Command(dockerBinary, "run", "-h", "testing", "-e=FALSE=true", "-e=TRUE", "-e=TRICKY", "busybox", "env")
+	cmd.Env = append(os.Environ(),
+		"TRUE=false",
+		"TRICKY=tri\ncky\n",
+	)
+
+	out, _, err := runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+
+	actualEnv := strings.Split(out, "\n")
+	if actualEnv[len(actualEnv)-1] == "" {
+		actualEnv = actualEnv[:len(actualEnv)-1]
+	}
+	sort.Strings(actualEnv)
+
+	goodEnv := []string{
+		"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
+		"HOME=/",
+		"HOSTNAME=testing",
+		"FALSE=true",
+		"TRUE=false",
+		"TRICKY=tri",
+		"cky",
+		"",
+	}
+	sort.Strings(goodEnv)
+	if len(goodEnv) != len(actualEnv) {
+		t.Fatalf("Wrong environment: should be %d variables, not: '%s'\n", len(goodEnv), strings.Join(actualEnv, ", "))
+	}
+	for i := range goodEnv {
+		if actualEnv[i] != goodEnv[i] {
+			t.Fatalf("Wrong environment variable: should be %s, not %s", goodEnv[i], actualEnv[i])
+		}
+	}
+
+	deleteAllContainers()
+
+	logDone("run - verify environment")
+}

+ 0 - 54
integration/container_test.go

@@ -306,60 +306,6 @@ func TestTty(t *testing.T) {
 	}
 }
 
-func TestEnv(t *testing.T) {
-	os.Setenv("TRUE", "false")
-	os.Setenv("TRICKY", "tri\ncky\n")
-	daemon := mkDaemon(t)
-	defer nuke(daemon)
-	config, _, _, err := runconfig.Parse([]string{"-e=FALSE=true", "-e=TRUE", "-e=TRICKY", GetTestImage(daemon).ID, "env"}, nil)
-	if err != nil {
-		t.Fatal(err)
-	}
-	container, _, err := daemon.Create(config, "")
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer daemon.Destroy(container)
-
-	stdout, err := container.StdoutPipe()
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer stdout.Close()
-	if err := container.Start(); err != nil {
-		t.Fatal(err)
-	}
-	container.Wait()
-	output, err := ioutil.ReadAll(stdout)
-	if err != nil {
-		t.Fatal(err)
-	}
-	actualEnv := strings.Split(string(output), "\n")
-	if actualEnv[len(actualEnv)-1] == "" {
-		actualEnv = actualEnv[:len(actualEnv)-1]
-	}
-	sort.Strings(actualEnv)
-	goodEnv := []string{
-		"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
-		"HOME=/",
-		"HOSTNAME=" + utils.TruncateID(container.ID),
-		"FALSE=true",
-		"TRUE=false",
-		"TRICKY=tri",
-		"cky",
-		"",
-	}
-	sort.Strings(goodEnv)
-	if len(goodEnv) != len(actualEnv) {
-		t.Fatalf("Wrong environment: should be %d variables, not: '%s'\n", len(goodEnv), strings.Join(actualEnv, ", "))
-	}
-	for i := range goodEnv {
-		if actualEnv[i] != goodEnv[i] {
-			t.Fatalf("Wrong environment variable: should be %s, not %s", goodEnv[i], actualEnv[i])
-		}
-	}
-}
-
 func TestEntrypoint(t *testing.T) {
 	daemon := mkDaemon(t)
 	defer nuke(daemon)