Some tests in `docker_api_containers_test.go` assume the
docker daemon is running at the same machine as the cli
and uses `ioutil.TempDir` to create temp dirs and use them
in the test.
On windows ioutil.TempDir and os.TempDir would create win-style
paths and pass them to daemon. Instead, I hardcoded `/tmp/` and
generate some random path manually and allow daemon to create
the directory.
Fixes tests:
- TestContainerApiStartVolumeBinds
- TestContainerApiStartDupVolumeBinds
- TestVolumesFromHasPriority
Downside:
- Does not clean the temp dirs generated on the remote daemon
machine unless delete container deletes them.
Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
| ... | ... |
@@ -4,8 +4,6 @@ import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"encoding/json" |
| 6 | 6 |
"io" |
| 7 |
- "io/ioutil" |
|
| 8 |
- "os" |
|
| 9 | 7 |
"os/exec" |
| 10 | 8 |
"strings" |
| 11 | 9 |
"testing" |
| ... | ... |
@@ -138,11 +136,7 @@ func TestContainerApiStartVolumeBinds(t *testing.T) {
|
| 138 | 138 |
t.Fatal(err) |
| 139 | 139 |
} |
| 140 | 140 |
|
| 141 |
- bindPath, err := ioutil.TempDir(os.TempDir(), "test") |
|
| 142 |
- if err != nil {
|
|
| 143 |
- t.Fatal(err) |
|
| 144 |
- } |
|
| 145 |
- |
|
| 141 |
+ bindPath := randomUnixTmpDirPath("test")
|
|
| 146 | 142 |
config = map[string]interface{}{
|
| 147 | 143 |
"Binds": []string{bindPath + ":/tmp"},
|
| 148 | 144 |
} |
| ... | ... |
@@ -175,16 +169,8 @@ func TestContainerApiStartDupVolumeBinds(t *testing.T) {
|
| 175 | 175 |
t.Fatal(err) |
| 176 | 176 |
} |
| 177 | 177 |
|
| 178 |
- bindPath1, err := ioutil.TempDir("", "test1")
|
|
| 179 |
- if err != nil {
|
|
| 180 |
- t.Fatal(err) |
|
| 181 |
- } |
|
| 182 |
- defer os.Remove(bindPath1) |
|
| 183 |
- bindPath2, err := ioutil.TempDir("", "test2")
|
|
| 184 |
- if err != nil {
|
|
| 185 |
- t.Fatal(err) |
|
| 186 |
- } |
|
| 187 |
- defer os.Remove(bindPath2) |
|
| 178 |
+ bindPath1 := randomUnixTmpDirPath("test1")
|
|
| 179 |
+ bindPath2 := randomUnixTmpDirPath("test2")
|
|
| 188 | 180 |
|
| 189 | 181 |
config = map[string]interface{}{
|
| 190 | 182 |
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
|
| ... | ... |
@@ -262,11 +248,7 @@ func TestVolumesFromHasPriority(t *testing.T) {
|
| 262 | 262 |
t.Fatal(err) |
| 263 | 263 |
} |
| 264 | 264 |
|
| 265 |
- bindPath, err := ioutil.TempDir(os.TempDir(), "test") |
|
| 266 |
- if err != nil {
|
|
| 267 |
- t.Fatal(err) |
|
| 268 |
- } |
|
| 269 |
- |
|
| 265 |
+ bindPath := randomUnixTmpDirPath("test")
|
|
| 270 | 266 |
config = map[string]interface{}{
|
| 271 | 267 |
"VolumesFrom": []string{volName},
|
| 272 | 268 |
"Binds": []string{bindPath + ":/tmp"},
|
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"net/http/httptest" |
| 11 | 11 |
"os" |
| 12 | 12 |
"os/exec" |
| 13 |
+ "path" |
|
| 13 | 14 |
"reflect" |
| 14 | 15 |
"strings" |
| 15 | 16 |
"syscall" |
| ... | ... |
@@ -241,6 +242,12 @@ func makeRandomString(n int) string {
|
| 241 | 241 |
return string(b) |
| 242 | 242 |
} |
| 243 | 243 |
|
| 244 |
+// randomUnixTmpDirPath provides a temporary unix path with rand string appended. |
|
| 245 |
+// does not create or checks if it exists. |
|
| 246 |
+func randomUnixTmpDirPath(s string) string {
|
|
| 247 |
+ return path.Join("/tmp", fmt.Sprintf("%s.%s", s, makeRandomString(10)))
|
|
| 248 |
+} |
|
| 249 |
+ |
|
| 244 | 250 |
// Reads chunkSize bytes from reader after every interval. |
| 245 | 251 |
// Returns total read bytes. |
| 246 | 252 |
func consumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) {
|