diff options
-rw-r--r-- | runsc/test/image/image_test.go | 20 | ||||
-rw-r--r-- | runsc/test/integration/exec_test.go | 2 | ||||
-rw-r--r-- | runsc/test/integration/integration_test.go | 6 | ||||
-rw-r--r-- | runsc/test/testutil/docker.go | 35 |
4 files changed, 44 insertions, 19 deletions
diff --git a/runsc/test/image/image_test.go b/runsc/test/image/image_test.go index 5f90ca9d2..1696de6f1 100644 --- a/runsc/test/image/image_test.go +++ b/runsc/test/image/image_test.go @@ -40,7 +40,7 @@ import ( func TestHelloWorld(t *testing.T) { d := testutil.MakeDocker("hello-test") - if _, err := d.Run("hello-world"); err != nil { + if err := d.Run("hello-world"); err != nil { t.Fatalf("docker run failed: %v", err) } defer d.CleanUp() @@ -94,7 +94,8 @@ func TestHttpd(t *testing.T) { } // Start the container. - if _, err := d.Run("-p", "80", "-v", testutil.MountArg(dir, "/usr/local/apache2/htdocs:ro"), "httpd"); err != nil { + mountArg := testutil.MountArg(dir, "/usr/local/apache2/htdocs", testutil.ReadOnly) + if err := d.Run("-p", "80", mountArg, "httpd"); err != nil { t.Fatalf("docker run failed: %v", err) } defer d.CleanUp() @@ -127,7 +128,8 @@ func TestNginx(t *testing.T) { } // Start the container. - if _, err := d.Run("-p", "80", "-v", testutil.MountArg(dir, "/usr/share/nginx/html:ro"), "nginx"); err != nil { + mountArg := testutil.MountArg(dir, "/usr/share/nginx/html", testutil.ReadOnly) + if err := d.Run("-p", "80", mountArg, "nginx"); err != nil { t.Fatalf("docker run failed: %v", err) } defer d.CleanUp() @@ -155,7 +157,7 @@ func TestMysql(t *testing.T) { d := testutil.MakeDocker("mysql-test") // Start the container. - if _, err := d.Run("-e", "MYSQL_ROOT_PASSWORD=foobar123", "mysql"); err != nil { + if err := d.Run("-e", "MYSQL_ROOT_PASSWORD=foobar123", "mysql"); err != nil { t.Fatalf("docker run failed: %v", err) } defer d.CleanUp() @@ -174,12 +176,12 @@ func TestMysql(t *testing.T) { // Tell mysql client to connect to the server and execute the file in verbose // mode to verify the output. args := []string{ - "--link", testutil.LinkArg(&d, "mysql"), - "-v", testutil.MountArg(dir, "/sql"), + testutil.LinkArg(&d, "mysql"), + testutil.MountArg(dir, "/sql", testutil.ReadWrite), "mysql", "mysql", "-hmysql", "-uroot", "-pfoobar123", "-v", "-e", "source /sql/mysql.sql", } - if _, err := client.Run(args...); err != nil { + if err := client.Run(args...); err != nil { t.Fatalf("docker run failed: %v", err) } defer client.CleanUp() @@ -198,7 +200,7 @@ func TestPythonHello(t *testing.T) { t.Fatalf("docker pull failed: %v", err) } d := testutil.MakeDocker("python-hello-test") - if _, err := d.Run("-p", "8080", "google/python-hello"); err != nil { + if err := d.Run("-p", "8080", "google/python-hello"); err != nil { t.Fatalf("docker run failed: %v", err) } defer d.CleanUp() @@ -230,7 +232,7 @@ func TestTomcat(t *testing.T) { t.Fatalf("docker pull failed: %v", err) } d := testutil.MakeDocker("tomcat-test") - if _, err := d.Run("-p", "8080", "tomcat:8.0"); err != nil { + if err := d.Run("-p", "8080", "tomcat:8.0"); err != nil { t.Fatalf("docker run failed: %v", err) } defer d.CleanUp() diff --git a/runsc/test/integration/exec_test.go b/runsc/test/integration/exec_test.go index 6053ecd1c..910c36597 100644 --- a/runsc/test/integration/exec_test.go +++ b/runsc/test/integration/exec_test.go @@ -40,7 +40,7 @@ func TestExecCapabilities(t *testing.T) { d := testutil.MakeDocker("exec-test") // Start the container. - if _, err := d.Run("alpine", "sh", "-c", "cat /proc/self/status; sleep 100"); err != nil { + if err := d.Run("alpine", "sh", "-c", "cat /proc/self/status; sleep 100"); err != nil { t.Fatalf("docker run failed: %v", err) } defer d.CleanUp() diff --git a/runsc/test/integration/integration_test.go b/runsc/test/integration/integration_test.go index 59df5bd7c..457b5fbf5 100644 --- a/runsc/test/integration/integration_test.go +++ b/runsc/test/integration/integration_test.go @@ -98,8 +98,8 @@ func TestPauseResume(t *testing.T) { t.Fatal("docker pull failed:", err) } d := testutil.MakeDocker("pause-resume-test") - if out, err := d.Run("-p", "8080", "google/python-hello"); err != nil { - t.Fatalf("docker run failed: %v\nout: %s", err, out) + if err := d.Run("-p", "8080", "google/python-hello"); err != nil { + t.Fatalf("docker run failed: %v", err) } defer d.CleanUp() @@ -157,7 +157,7 @@ func TestConnectToSelf(t *testing.T) { // Creates server that replies "server" and exists. Sleeps at the end because // 'docker exec' gets killed if the init process exists before it can finish. - if _, err := d.Run("ubuntu:trusty", "/bin/sh", "-c", "echo server | nc -l -p 8080 && sleep 1"); err != nil { + if err := d.Run("ubuntu:trusty", "/bin/sh", "-c", "echo server | nc -l -p 8080 && sleep 1"); err != nil { t.Fatal("docker run failed:", err) } defer d.CleanUp() diff --git a/runsc/test/testutil/docker.go b/runsc/test/testutil/docker.go index d0446df4e..7f5909987 100644 --- a/runsc/test/testutil/docker.go +++ b/runsc/test/testutil/docker.go @@ -65,14 +65,35 @@ func EnsureSupportedDockerVersion() { } } +// MountMode describes if the mount should be ro or rw. +type MountMode int + +const ( + // ReadOnly is what the name says. + ReadOnly MountMode = iota + // ReadWrite is what the name says. + ReadWrite +) + +// String returns the mount mode argument for this MountMode. +func (m MountMode) String() string { + switch m { + case ReadOnly: + return "ro" + case ReadWrite: + return "rw" + } + panic(fmt.Sprintf("invalid mode: %d", m)) +} + // MountArg formats the volume argument to mount in the container. -func MountArg(source, target string) string { - return fmt.Sprintf("%s:%s", source, target) +func MountArg(source, target string, mode MountMode) string { + return fmt.Sprintf("-v=%s:%s:%v", source, target, mode) } // LinkArg formats the link argument. func LinkArg(source *Docker, target string) string { - return fmt.Sprintf("%s:%s", source.Name, target) + return fmt.Sprintf("--link=%s:%s", source.Name, target) } // PrepareFiles creates temp directory to copy files there. The sandbox doesn't @@ -155,11 +176,13 @@ func (d *Docker) Stop() error { return nil } -// Run calls 'docker run' with the arguments provided. -func (d *Docker) Run(args ...string) (string, error) { +// Run calls 'docker run' with the arguments provided. The container starts +// running in the backgroud and the call returns immediately. +func (d *Docker) Run(args ...string) error { a := []string{"run", "--runtime", d.Runtime, "--name", d.Name, "-d"} a = append(a, args...) - return do(a...) + _, err := do(a...) + return err } // Logs calls 'docker logs'. |