2013-01-18 19:13:39 -05:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2013-01-28 14:51:51 -05:00
|
|
|
"fmt"
|
2013-01-29 18:16:45 -05:00
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
2013-03-11 22:15:29 -04:00
|
|
|
"os"
|
2013-05-13 19:39:54 -04:00
|
|
|
"path"
|
2013-02-13 20:24:35 -05:00
|
|
|
"strings"
|
2013-01-18 19:13:39 -05:00
|
|
|
"testing"
|
2013-01-28 14:51:51 -05:00
|
|
|
"time"
|
2014-06-06 07:30:04 -04:00
|
|
|
|
2014-07-24 18:19:50 -04:00
|
|
|
"github.com/docker/docker/runconfig"
|
2013-01-18 19:13:39 -05:00
|
|
|
)
|
|
|
|
|
2013-04-11 19:21:19 -04:00
|
|
|
func TestKillDifferentUser(t *testing.T) {
|
2014-04-17 17:43:01 -04:00
|
|
|
daemon := mkDaemon(t)
|
|
|
|
defer nuke(daemon)
|
2013-08-09 13:50:58 -04:00
|
|
|
|
2014-04-17 17:43:01 -04:00
|
|
|
container, _, err := daemon.Create(&runconfig.Config{
|
|
|
|
Image: GetTestImage(daemon).ID,
|
2013-08-09 13:50:58 -04:00
|
|
|
Cmd: []string{"cat"},
|
|
|
|
OpenStdin: true,
|
|
|
|
User: "daemon",
|
2013-04-11 19:21:19 -04:00
|
|
|
},
|
2013-10-28 19:58:59 -04:00
|
|
|
"",
|
2013-04-11 19:21:19 -04:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-04-17 17:43:01 -04:00
|
|
|
defer daemon.Destroy(container)
|
2013-11-14 01:10:20 -05:00
|
|
|
// FIXME @shykes: this seems redundant, but is very old, I'm leaving it in case
|
|
|
|
// there is a side effect I'm not seeing.
|
|
|
|
// defer container.stdin.Close()
|
2013-04-11 19:21:19 -04:00
|
|
|
|
2013-11-21 15:21:03 -05:00
|
|
|
if container.State.IsRunning() {
|
2013-04-11 19:21:19 -04:00
|
|
|
t.Errorf("Container shouldn't be running")
|
|
|
|
}
|
2013-10-31 17:58:43 -04:00
|
|
|
if err := container.Start(); err != nil {
|
2013-04-11 19:21:19 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-07-02 06:47:37 -04:00
|
|
|
setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
|
2013-11-21 15:21:03 -05:00
|
|
|
for !container.State.IsRunning() {
|
2013-07-01 20:19:39 -04:00
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
}
|
|
|
|
})
|
2013-04-11 19:21:19 -04:00
|
|
|
|
2013-08-09 13:50:58 -04:00
|
|
|
setTimeout(t, "read/write assertion timed out", 2*time.Second, func() {
|
|
|
|
out, _ := container.StdoutPipe()
|
|
|
|
in, _ := container.StdinPipe()
|
2013-11-28 19:12:45 -05:00
|
|
|
if err := assertPipe("hello\n", "hello", out, in, 150); err != nil {
|
2013-08-09 13:50:58 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
2013-07-02 06:47:37 -04:00
|
|
|
|
2013-04-11 19:21:19 -04:00
|
|
|
if err := container.Kill(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-11-21 15:21:03 -05:00
|
|
|
if container.State.IsRunning() {
|
2013-04-11 19:21:19 -04:00
|
|
|
t.Errorf("Container shouldn't be running")
|
|
|
|
}
|
2014-06-06 07:30:04 -04:00
|
|
|
container.State.WaitStop(-1 * time.Second)
|
2013-11-21 15:21:03 -05:00
|
|
|
if container.State.IsRunning() {
|
2013-04-11 19:21:19 -04:00
|
|
|
t.Errorf("Container shouldn't be running")
|
|
|
|
}
|
|
|
|
// Try stopping twice
|
|
|
|
if err := container.Kill(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 22:05:57 -05:00
|
|
|
func TestRestartStdin(t *testing.T) {
|
2014-04-17 17:43:01 -04:00
|
|
|
daemon := mkDaemon(t)
|
|
|
|
defer nuke(daemon)
|
|
|
|
container, _, err := daemon.Create(&runconfig.Config{
|
|
|
|
Image: GetTestImage(daemon).ID,
|
2013-03-23 15:39:09 -04:00
|
|
|
Cmd: []string{"cat"},
|
2013-03-23 15:16:58 -04:00
|
|
|
|
|
|
|
OpenStdin: true,
|
|
|
|
},
|
2013-10-28 19:58:59 -04:00
|
|
|
"",
|
2013-02-13 22:05:57 -05:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-04-17 17:43:01 -04:00
|
|
|
defer daemon.Destroy(container)
|
2013-02-13 22:05:57 -05:00
|
|
|
|
|
|
|
stdin, err := container.StdinPipe()
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-02-13 22:05:57 -05:00
|
|
|
stdout, err := container.StdoutPipe()
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-10-31 17:58:43 -04:00
|
|
|
if err := container.Start(); err != nil {
|
2013-02-13 22:05:57 -05:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-29 10:44:58 -04:00
|
|
|
if _, err := io.WriteString(stdin, "hello world"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := stdin.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-06-06 07:30:04 -04:00
|
|
|
container.State.WaitStop(-1 * time.Second)
|
2013-02-13 22:05:57 -05:00
|
|
|
output, err := ioutil.ReadAll(stdout)
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := stdout.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-02-13 22:05:57 -05:00
|
|
|
if string(output) != "hello world" {
|
2013-03-29 10:44:58 -04:00
|
|
|
t.Fatalf("Unexpected output. Expected %s, received: %s", "hello world", string(output))
|
2013-02-13 22:05:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restart and try again
|
|
|
|
stdin, err = container.StdinPipe()
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-02-13 22:05:57 -05:00
|
|
|
stdout, err = container.StdoutPipe()
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-10-31 17:58:43 -04:00
|
|
|
if err := container.Start(); err != nil {
|
2013-02-13 22:05:57 -05:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-29 10:44:58 -04:00
|
|
|
if _, err := io.WriteString(stdin, "hello world #2"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := stdin.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-06-06 07:30:04 -04:00
|
|
|
container.State.WaitStop(-1 * time.Second)
|
2013-02-13 22:05:57 -05:00
|
|
|
output, err = ioutil.ReadAll(stdout)
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := stdout.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-02-13 22:05:57 -05:00
|
|
|
if string(output) != "hello world #2" {
|
2013-03-29 10:44:58 -04:00
|
|
|
t.Fatalf("Unexpected output. Expected %s, received: %s", "hello world #2", string(output))
|
2013-02-13 22:05:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 18:16:45 -05:00
|
|
|
func TestStdin(t *testing.T) {
|
2014-04-17 17:43:01 -04:00
|
|
|
daemon := mkDaemon(t)
|
|
|
|
defer nuke(daemon)
|
|
|
|
container, _, err := daemon.Create(&runconfig.Config{
|
|
|
|
Image: GetTestImage(daemon).ID,
|
2013-03-23 15:39:09 -04:00
|
|
|
Cmd: []string{"cat"},
|
2013-03-23 15:16:58 -04:00
|
|
|
|
|
|
|
OpenStdin: true,
|
|
|
|
},
|
2013-10-28 19:58:59 -04:00
|
|
|
"",
|
2013-01-29 18:16:45 -05:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-04-17 17:43:01 -04:00
|
|
|
defer daemon.Destroy(container)
|
2013-01-29 18:16:45 -05:00
|
|
|
|
|
|
|
stdin, err := container.StdinPipe()
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-01-29 18:16:45 -05:00
|
|
|
stdout, err := container.StdoutPipe()
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-10-31 17:58:43 -04:00
|
|
|
if err := container.Start(); err != nil {
|
2013-03-29 10:44:58 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-01-29 18:16:45 -05:00
|
|
|
defer stdin.Close()
|
|
|
|
defer stdout.Close()
|
2013-03-29 10:44:58 -04:00
|
|
|
if _, err := io.WriteString(stdin, "hello world"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := stdin.Close(); err != nil {
|
2013-01-29 18:16:45 -05:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-06-06 07:30:04 -04:00
|
|
|
container.State.WaitStop(-1 * time.Second)
|
2013-01-29 18:16:45 -05:00
|
|
|
output, err := ioutil.ReadAll(stdout)
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-01-29 18:16:45 -05:00
|
|
|
if string(output) != "hello world" {
|
2013-03-29 10:44:58 -04:00
|
|
|
t.Fatalf("Unexpected output. Expected %s, received: %s", "hello world", string(output))
|
2013-01-29 18:16:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTty(t *testing.T) {
|
2014-04-17 17:43:01 -04:00
|
|
|
daemon := mkDaemon(t)
|
|
|
|
defer nuke(daemon)
|
|
|
|
container, _, err := daemon.Create(&runconfig.Config{
|
|
|
|
Image: GetTestImage(daemon).ID,
|
2013-03-23 15:39:09 -04:00
|
|
|
Cmd: []string{"cat"},
|
2013-03-23 15:16:58 -04:00
|
|
|
|
|
|
|
OpenStdin: true,
|
|
|
|
},
|
2013-10-28 19:58:59 -04:00
|
|
|
"",
|
2013-01-29 18:16:45 -05:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-04-17 17:43:01 -04:00
|
|
|
defer daemon.Destroy(container)
|
2013-01-29 18:16:45 -05:00
|
|
|
|
|
|
|
stdin, err := container.StdinPipe()
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-01-29 18:16:45 -05:00
|
|
|
stdout, err := container.StdoutPipe()
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-10-31 17:58:43 -04:00
|
|
|
if err := container.Start(); err != nil {
|
2013-03-29 10:44:58 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-01-29 18:16:45 -05:00
|
|
|
defer stdin.Close()
|
|
|
|
defer stdout.Close()
|
2013-03-29 10:44:58 -04:00
|
|
|
if _, err := io.WriteString(stdin, "hello world"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := stdin.Close(); err != nil {
|
2013-01-29 18:16:45 -05:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-06-06 07:30:04 -04:00
|
|
|
container.State.WaitStop(-1 * time.Second)
|
2013-01-29 18:16:45 -05:00
|
|
|
output, err := ioutil.ReadAll(stdout)
|
2013-03-29 10:44:58 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-01-29 18:16:45 -05:00
|
|
|
if string(output) != "hello world" {
|
2013-03-29 10:44:58 -04:00
|
|
|
t.Fatalf("Unexpected output. Expected %s, received: %s", "hello world", string(output))
|
2013-01-29 18:16:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 22:20:05 -04:00
|
|
|
func TestEntrypoint(t *testing.T) {
|
2014-04-17 17:43:01 -04:00
|
|
|
daemon := mkDaemon(t)
|
|
|
|
defer nuke(daemon)
|
|
|
|
container, _, err := daemon.Create(
|
2014-02-11 23:04:39 -05:00
|
|
|
&runconfig.Config{
|
2014-04-17 17:43:01 -04:00
|
|
|
Image: GetTestImage(daemon).ID,
|
2013-06-24 22:20:05 -04:00
|
|
|
Entrypoint: []string{"/bin/echo"},
|
|
|
|
Cmd: []string{"-n", "foobar"},
|
|
|
|
},
|
2013-10-28 19:58:59 -04:00
|
|
|
"",
|
2013-06-24 22:20:05 -04:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-04-17 17:43:01 -04:00
|
|
|
defer daemon.Destroy(container)
|
2013-06-24 22:20:05 -04:00
|
|
|
output, err := container.Output()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if string(output) != "foobar" {
|
|
|
|
t.Error(string(output))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-05 10:03:42 -04:00
|
|
|
func TestEntrypointNoCmd(t *testing.T) {
|
2014-04-17 17:43:01 -04:00
|
|
|
daemon := mkDaemon(t)
|
|
|
|
defer nuke(daemon)
|
|
|
|
container, _, err := daemon.Create(
|
2014-02-11 23:04:39 -05:00
|
|
|
&runconfig.Config{
|
2014-04-17 17:43:01 -04:00
|
|
|
Image: GetTestImage(daemon).ID,
|
2013-08-05 10:03:42 -04:00
|
|
|
Entrypoint: []string{"/bin/echo", "foobar"},
|
|
|
|
},
|
2013-10-28 19:58:59 -04:00
|
|
|
"",
|
2013-08-05 10:03:42 -04:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-04-17 17:43:01 -04:00
|
|
|
defer daemon.Destroy(container)
|
2013-08-05 10:03:42 -04:00
|
|
|
output, err := container.Output()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if strings.Trim(string(output), "\r\n") != "foobar" {
|
|
|
|
t.Error(string(output))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-15 11:34:49 -04:00
|
|
|
func BenchmarkRunSequential(b *testing.B) {
|
2014-04-17 17:43:01 -04:00
|
|
|
daemon := mkDaemon(b)
|
|
|
|
defer nuke(daemon)
|
2013-01-28 14:51:51 -05:00
|
|
|
for i := 0; i < b.N; i++ {
|
2014-04-17 17:43:01 -04:00
|
|
|
container, _, err := daemon.Create(&runconfig.Config{
|
|
|
|
Image: GetTestImage(daemon).ID,
|
2013-03-23 15:39:09 -04:00
|
|
|
Cmd: []string{"echo", "-n", "foo"},
|
2013-03-23 15:16:58 -04:00
|
|
|
},
|
2013-10-28 19:58:59 -04:00
|
|
|
"",
|
2013-01-28 14:51:51 -05:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
2014-04-17 17:43:01 -04:00
|
|
|
defer daemon.Destroy(container)
|
2013-01-28 14:51:51 -05:00
|
|
|
output, err := container.Output()
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
if string(output) != "foo" {
|
2013-03-30 03:22:56 -04:00
|
|
|
b.Fatalf("Unexpected output: %s", output)
|
2013-01-28 14:51:51 -05:00
|
|
|
}
|
2014-04-17 17:43:01 -04:00
|
|
|
if err := daemon.Destroy(container); err != nil {
|
2013-01-28 14:51:51 -05:00
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkRunParallel(b *testing.B) {
|
2014-04-17 17:43:01 -04:00
|
|
|
daemon := mkDaemon(b)
|
|
|
|
defer nuke(daemon)
|
2013-01-28 14:51:51 -05:00
|
|
|
|
|
|
|
var tasks []chan error
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
complete := make(chan error)
|
|
|
|
tasks = append(tasks, complete)
|
|
|
|
go func(i int, complete chan error) {
|
2014-04-17 17:43:01 -04:00
|
|
|
container, _, err := daemon.Create(&runconfig.Config{
|
|
|
|
Image: GetTestImage(daemon).ID,
|
2013-03-23 15:39:09 -04:00
|
|
|
Cmd: []string{"echo", "-n", "foo"},
|
2013-03-23 15:16:58 -04:00
|
|
|
},
|
2013-10-28 19:58:59 -04:00
|
|
|
"",
|
2013-01-28 14:51:51 -05:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
complete <- err
|
|
|
|
return
|
|
|
|
}
|
2014-04-17 17:43:01 -04:00
|
|
|
defer daemon.Destroy(container)
|
2013-10-31 17:58:43 -04:00
|
|
|
if err := container.Start(); err != nil {
|
2013-01-28 14:51:51 -05:00
|
|
|
complete <- err
|
|
|
|
return
|
|
|
|
}
|
2014-06-06 07:30:04 -04:00
|
|
|
if _, err := container.State.WaitStop(15 * time.Second); err != nil {
|
2013-01-28 14:51:51 -05:00
|
|
|
complete <- err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// if string(output) != "foo" {
|
|
|
|
// complete <- fmt.Errorf("Unexecpted output: %v", string(output))
|
|
|
|
// }
|
2014-04-17 17:43:01 -04:00
|
|
|
if err := daemon.Destroy(container); err != nil {
|
2013-01-28 14:51:51 -05:00
|
|
|
complete <- err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
complete <- nil
|
|
|
|
}(i, complete)
|
|
|
|
}
|
|
|
|
var errors []error
|
|
|
|
for _, task := range tasks {
|
|
|
|
err := <-task
|
|
|
|
if err != nil {
|
|
|
|
errors = append(errors, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(errors) > 0 {
|
|
|
|
b.Fatal(errors)
|
|
|
|
}
|
|
|
|
}
|
2013-05-13 19:39:54 -04:00
|
|
|
|
2013-06-25 02:30:48 -04:00
|
|
|
func tempDir(t *testing.T) string {
|
2013-10-16 16:44:15 -04:00
|
|
|
tmpDir, err := ioutil.TempDir("", "docker-test-container")
|
2013-05-13 19:39:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-06-25 02:30:48 -04:00
|
|
|
return tmpDir
|
|
|
|
}
|
2013-05-13 19:39:54 -04:00
|
|
|
|
2013-06-25 02:30:48 -04:00
|
|
|
func TestBindMounts(t *testing.T) {
|
2013-11-14 15:33:15 -05:00
|
|
|
eng := NewTestEngine(t)
|
2014-04-17 17:43:01 -04:00
|
|
|
r := mkDaemonFromEngine(eng, t)
|
2013-11-14 15:33:15 -05:00
|
|
|
defer r.Nuke()
|
|
|
|
|
2013-06-25 02:30:48 -04:00
|
|
|
tmpDir := tempDir(t)
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
writeFile(path.Join(tmpDir, "touch-me"), "", t)
|
|
|
|
|
|
|
|
// Test reading from a read-only bind mount
|
2013-11-14 15:33:15 -05:00
|
|
|
stdout, _ := runContainer(eng, r, []string{"-v", fmt.Sprintf("%s:/tmp:ro", tmpDir), "_", "ls", "/tmp"}, t)
|
2013-06-25 02:30:48 -04:00
|
|
|
if !strings.Contains(stdout, "touch-me") {
|
2013-05-13 19:39:54 -04:00
|
|
|
t.Fatal("Container failed to read from bind mount")
|
|
|
|
}
|
2013-06-25 02:30:48 -04:00
|
|
|
|
2013-05-13 19:39:54 -04:00
|
|
|
// test writing to bind mount
|
2013-11-14 15:33:15 -05:00
|
|
|
runContainer(eng, r, []string{"-v", fmt.Sprintf("%s:/tmp:rw", tmpDir), "_", "touch", "/tmp/holla"}, t)
|
2013-06-26 15:04:55 -04:00
|
|
|
readFile(path.Join(tmpDir, "holla"), t) // Will fail if the file doesn't exist
|
2013-05-13 19:39:54 -04:00
|
|
|
|
|
|
|
// test mounting to an illegal destination directory
|
2013-11-14 15:33:15 -05:00
|
|
|
if _, err := runContainer(eng, r, []string{"-v", fmt.Sprintf("%s:.", tmpDir), "_", "ls", "."}, nil); err == nil {
|
2013-05-13 19:39:54 -04:00
|
|
|
t.Fatal("Container bind mounted illegal directory")
|
2013-06-25 02:30:48 -04:00
|
|
|
}
|
2013-11-19 18:27:01 -05:00
|
|
|
|
|
|
|
// test mount a file
|
|
|
|
runContainer(eng, r, []string{"-v", fmt.Sprintf("%s/holla:/tmp/holla:rw", tmpDir), "_", "sh", "-c", "echo -n 'yotta' > /tmp/holla"}, t)
|
|
|
|
content := readFile(path.Join(tmpDir, "holla"), t) // Will fail if the file doesn't exist
|
|
|
|
if content != "yotta" {
|
|
|
|
t.Fatal("Container failed to write to bind mount file")
|
|
|
|
}
|
2013-05-13 19:39:54 -04:00
|
|
|
}
|