|
@@ -7,6 +7,7 @@ import (
|
|
|
"io/ioutil"
|
|
|
"math/rand"
|
|
|
"os"
|
|
|
+ "path"
|
|
|
"regexp"
|
|
|
"sort"
|
|
|
"strings"
|
|
@@ -15,10 +16,7 @@ import (
|
|
|
)
|
|
|
|
|
|
func TestIDFormat(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container1, err := NewBuilder(runtime).Create(
|
|
|
&Config{
|
|
@@ -39,10 +37,7 @@ func TestIDFormat(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestMultipleAttachRestart(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(
|
|
|
&Config{
|
|
@@ -70,7 +65,8 @@ func TestMultipleAttachRestart(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
l1, err := bufio.NewReader(stdout1).ReadString('\n')
|
|
@@ -111,7 +107,7 @@ func TestMultipleAttachRestart(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
@@ -142,10 +138,7 @@ func TestMultipleAttachRestart(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestDiff(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
builder := NewBuilder(runtime)
|
|
@@ -251,10 +244,7 @@ func TestDiff(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestCommitAutoRun(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
builder := NewBuilder(runtime)
|
|
@@ -306,7 +296,8 @@ func TestCommitAutoRun(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if err := container2.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container2.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
container2.Wait()
|
|
@@ -330,10 +321,7 @@ func TestCommitAutoRun(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestCommitRun(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
builder := NewBuilder(runtime)
|
|
@@ -388,7 +376,8 @@ func TestCommitRun(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if err := container2.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container2.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
container2.Wait()
|
|
@@ -412,10 +401,7 @@ func TestCommitRun(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestStart(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(
|
|
|
&Config{
|
|
@@ -436,7 +422,8 @@ func TestStart(t *testing.T) {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
@@ -446,7 +433,7 @@ func TestStart(t *testing.T) {
|
|
|
if !container.State.Running {
|
|
|
t.Errorf("Container should be running")
|
|
|
}
|
|
|
- if err := container.Start(); err == nil {
|
|
|
+ if err := container.Start(hostConfig); err == nil {
|
|
|
t.Fatalf("A running containter should be able to be started")
|
|
|
}
|
|
|
|
|
@@ -456,10 +443,7 @@ func TestStart(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestRun(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(
|
|
|
&Config{
|
|
@@ -484,10 +468,7 @@ func TestRun(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestOutput(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(
|
|
|
&Config{
|
|
@@ -509,10 +490,7 @@ func TestOutput(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestKillDifferentUser(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(&Config{
|
|
|
Image: GetTestImage(runtime).ID,
|
|
@@ -528,7 +506,8 @@ func TestKillDifferentUser(t *testing.T) {
|
|
|
if container.State.Running {
|
|
|
t.Errorf("Container shouldn't be running")
|
|
|
}
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
@@ -558,13 +537,10 @@ func TestKillDifferentUser(t *testing.T) {
|
|
|
|
|
|
// Test that creating a container with a volume doesn't crash. Regression test for #995.
|
|
|
func TestCreateVolume(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
- config, _, err := ParseRun([]string{"-v", "/var/lib/data", GetTestImage(runtime).ID, "echo", "hello", "world"}, nil)
|
|
|
+ config, hc, _, err := ParseRun([]string{"-v", "/var/lib/data", GetTestImage(runtime).ID, "echo", "hello", "world"}, nil)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
@@ -573,7 +549,7 @@ func TestCreateVolume(t *testing.T) {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
defer runtime.Destroy(c)
|
|
|
- if err := c.Start(); err != nil {
|
|
|
+ if err := c.Start(hc); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
c.WaitTimeout(500 * time.Millisecond)
|
|
@@ -581,10 +557,7 @@ func TestCreateVolume(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestKill(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(&Config{
|
|
|
Image: GetTestImage(runtime).ID,
|
|
@@ -599,7 +572,8 @@ func TestKill(t *testing.T) {
|
|
|
if container.State.Running {
|
|
|
t.Errorf("Container shouldn't be running")
|
|
|
}
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
@@ -626,10 +600,7 @@ func TestKill(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestExitCode(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
builder := NewBuilder(runtime)
|
|
@@ -666,10 +637,7 @@ func TestExitCode(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestRestart(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(&Config{
|
|
|
Image: GetTestImage(runtime).ID,
|
|
@@ -699,10 +667,7 @@ func TestRestart(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestRestartStdin(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(&Config{
|
|
|
Image: GetTestImage(runtime).ID,
|
|
@@ -724,7 +689,8 @@ func TestRestartStdin(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
if _, err := io.WriteString(stdin, "hello world"); err != nil {
|
|
@@ -754,7 +720,7 @@ func TestRestartStdin(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
if _, err := io.WriteString(stdin, "hello world #2"); err != nil {
|
|
@@ -777,10 +743,7 @@ func TestRestartStdin(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestUser(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
builder := NewBuilder(runtime)
|
|
@@ -887,10 +850,7 @@ func TestUser(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestMultipleContainers(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
builder := NewBuilder(runtime)
|
|
@@ -916,10 +876,11 @@ func TestMultipleContainers(t *testing.T) {
|
|
|
defer runtime.Destroy(container2)
|
|
|
|
|
|
// Start both containers
|
|
|
- if err := container1.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container1.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if err := container2.Start(); err != nil {
|
|
|
+ if err := container2.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
@@ -946,10 +907,7 @@ func TestMultipleContainers(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestStdin(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(&Config{
|
|
|
Image: GetTestImage(runtime).ID,
|
|
@@ -971,7 +929,8 @@ func TestStdin(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
defer stdin.Close()
|
|
@@ -993,10 +952,7 @@ func TestStdin(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestTty(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(&Config{
|
|
|
Image: GetTestImage(runtime).ID,
|
|
@@ -1018,7 +974,8 @@ func TestTty(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
defer stdin.Close()
|
|
@@ -1040,10 +997,7 @@ func TestTty(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestEnv(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
container, err := NewBuilder(runtime).Create(&Config{
|
|
|
Image: GetTestImage(runtime).ID,
|
|
@@ -1060,7 +1014,8 @@ func TestEnv(t *testing.T) {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
defer stdout.Close()
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
container.Wait()
|
|
@@ -1109,10 +1064,7 @@ func grepFile(t *testing.T, path string, pattern string) {
|
|
|
}
|
|
|
|
|
|
func TestLXCConfig(t *testing.T) {
|
|
|
- runtime, err := newTestRuntime()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
+ runtime := mkRuntime(t)
|
|
|
defer nuke(runtime)
|
|
|
// Memory is allocated randomly for testing
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
@@ -1196,7 +1148,8 @@ func BenchmarkRunParallel(b *testing.B) {
|
|
|
return
|
|
|
}
|
|
|
defer runtime.Destroy(container)
|
|
|
- if err := container.Start(); err != nil {
|
|
|
+ hostConfig := &HostConfig{}
|
|
|
+ if err := container.Start(hostConfig); err != nil {
|
|
|
complete <- err
|
|
|
return
|
|
|
}
|
|
@@ -1225,3 +1178,35 @@ func BenchmarkRunParallel(b *testing.B) {
|
|
|
b.Fatal(errors)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func tempDir(t *testing.T) string {
|
|
|
+ tmpDir, err := ioutil.TempDir("", "docker-test")
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ return tmpDir
|
|
|
+}
|
|
|
+
|
|
|
+func TestBindMounts(t *testing.T) {
|
|
|
+ r := mkRuntime(t)
|
|
|
+ defer nuke(r)
|
|
|
+ tmpDir := tempDir(t)
|
|
|
+ defer os.RemoveAll(tmpDir)
|
|
|
+ writeFile(path.Join(tmpDir, "touch-me"), "", t)
|
|
|
+
|
|
|
+ // Test reading from a read-only bind mount
|
|
|
+ stdout, _ := runContainer(r, []string{"-b", fmt.Sprintf("%s:/tmp:ro", tmpDir), "_", "ls", "/tmp"}, t)
|
|
|
+ if !strings.Contains(stdout, "touch-me") {
|
|
|
+ t.Fatal("Container failed to read from bind mount")
|
|
|
+ }
|
|
|
+
|
|
|
+ // test writing to bind mount
|
|
|
+ runContainer(r, []string{"-b", fmt.Sprintf("%s:/tmp:rw", tmpDir), "_", "touch", "/tmp/holla"}, t)
|
|
|
+ readFile(path.Join(tmpDir, "holla"), t) // Will fail if the file doesn't exist
|
|
|
+
|
|
|
+ // test mounting to an illegal destination directory
|
|
|
+ if _, err := runContainer(r, []string{"-b", fmt.Sprintf("%s:.", tmpDir), "ls", "."}, nil); err == nil {
|
|
|
+ t.Fatal("Container bind mounted illegal directory")
|
|
|
+
|
|
|
+ }
|
|
|
+}
|