소스 검색

Merge pull request #10794 from ahmetalpbalkan/win-cli/TestContainerApi-volume-path-fix

integration-cli: Generate unix-style volume paths for tests
Jessie Frazelle 10 년 전
부모
커밋
47e9f90be1
2개의 변경된 파일11개의 추가작업 그리고 22개의 파일을 삭제
  1. 4 22
      integration-cli/docker_api_containers_test.go
  2. 7 0
      integration-cli/utils.go

+ 4 - 22
integration-cli/docker_api_containers_test.go

@@ -4,8 +4,6 @@ import (
 	"bytes"
 	"encoding/json"
 	"io"
-	"io/ioutil"
-	"os"
 	"os/exec"
 	"strings"
 	"testing"
@@ -138,11 +136,7 @@ func TestContainerApiStartVolumeBinds(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	bindPath, err := ioutil.TempDir(os.TempDir(), "test")
-	if err != nil {
-		t.Fatal(err)
-	}
-
+	bindPath := randomUnixTmpDirPath("test")
 	config = map[string]interface{}{
 		"Binds": []string{bindPath + ":/tmp"},
 	}
@@ -175,16 +169,8 @@ func TestContainerApiStartDupVolumeBinds(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	bindPath1, err := ioutil.TempDir("", "test1")
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer os.Remove(bindPath1)
-	bindPath2, err := ioutil.TempDir("", "test2")
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer os.Remove(bindPath2)
+	bindPath1 := randomUnixTmpDirPath("test1")
+	bindPath2 := randomUnixTmpDirPath("test2")
 
 	config = map[string]interface{}{
 		"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
@@ -262,11 +248,7 @@ func TestVolumesFromHasPriority(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	bindPath, err := ioutil.TempDir(os.TempDir(), "test")
-	if err != nil {
-		t.Fatal(err)
-	}
-
+	bindPath := randomUnixTmpDirPath("test")
 	config = map[string]interface{}{
 		"VolumesFrom": []string{volName},
 		"Binds":       []string{bindPath + ":/tmp"},

+ 7 - 0
integration-cli/utils.go

@@ -11,6 +11,7 @@ import (
 	"net/http/httptest"
 	"os"
 	"os/exec"
+	"path"
 	"reflect"
 	"strings"
 	"syscall"
@@ -277,6 +278,12 @@ func makeRandomString(n int) string {
 	return string(b)
 }
 
+// randomUnixTmpDirPath provides a temporary unix path with rand string appended.
+// does not create or checks if it exists.
+func randomUnixTmpDirPath(s string) string {
+	return path.Join("/tmp", fmt.Sprintf("%s.%s", s, makeRandomString(10)))
+}
+
 // Reads chunkSize bytes from reader after every interval.
 // Returns total read bytes.
 func consumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) {