Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
LK4D4 authored on 2014/05/23 04:16:27... | ... |
@@ -10,6 +10,25 @@ import ( |
10 | 10 |
"time" |
11 | 11 |
) |
12 | 12 |
|
13 |
+func checkSimpleBuild(t *testing.T, dockerfile, name, inspectFormat, expected string) { |
|
14 |
+ buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-") |
|
15 |
+ buildCmd.Stdin = strings.NewReader(dockerfile) |
|
16 |
+ out, exitCode, err := runCommandWithOutput(buildCmd) |
|
17 |
+ errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err)) |
|
18 |
+ if err != nil || exitCode != 0 { |
|
19 |
+ t.Fatal("failed to build the image") |
|
20 |
+ } |
|
21 |
+ inspectCmd := exec.Command(dockerBinary, "inspect", "-f", inspectFormat, name) |
|
22 |
+ out, exitCode, err = runCommandWithOutput(inspectCmd) |
|
23 |
+ if err != nil || exitCode != 0 { |
|
24 |
+ t.Fatalf("failed to inspect the image: %s", out) |
|
25 |
+ } |
|
26 |
+ out = strings.TrimSpace(out) |
|
27 |
+ if out != expected { |
|
28 |
+ t.Fatalf("From format %s expected %s, got %s", inspectFormat, expected, out) |
|
29 |
+ } |
|
30 |
+} |
|
31 |
+ |
|
13 | 32 |
func TestBuildCacheADD(t *testing.T) { |
14 | 33 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1") |
15 | 34 |
buildCmd := exec.Command(dockerBinary, "build", "-t", "testcacheadd1", ".") |
... | ... |
@@ -413,6 +432,20 @@ func TestBuildRm(t *testing.T) { |
413 | 413 |
logDone("build - ensure --rm=false overrides the default") |
414 | 414 |
} |
415 | 415 |
|
416 |
+func TestBuildWithVolume(t *testing.T) { |
|
417 |
+ checkSimpleBuild(t, |
|
418 |
+ ` |
|
419 |
+ FROM scratch |
|
420 |
+ VOLUME /test |
|
421 |
+ `, |
|
422 |
+ "testbuildimg", |
|
423 |
+ "{{json .config.Volumes}}", |
|
424 |
+ `{"/test":{}}`) |
|
425 |
+ |
|
426 |
+ deleteImages("testbuildimg") |
|
427 |
+ logDone("build - with volume") |
|
428 |
+} |
|
429 |
+ |
|
416 | 430 |
// TODO: TestCaching |
417 | 431 |
|
418 | 432 |
// TODO: TestADDCacheInvalidation |
... | ... |
@@ -414,26 +414,6 @@ func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, u |
414 | 414 |
return image, err |
415 | 415 |
} |
416 | 416 |
|
417 |
-func TestVolume(t *testing.T) { |
|
418 |
- img, err := buildImage(testContextTemplate{` |
|
419 |
- from {IMAGE} |
|
420 |
- volume /test |
|
421 |
- cmd Hello world |
|
422 |
- `, nil, nil}, t, nil, true) |
|
423 |
- if err != nil { |
|
424 |
- t.Fatal(err) |
|
425 |
- } |
|
426 |
- |
|
427 |
- if len(img.Config.Volumes) == 0 { |
|
428 |
- t.Fail() |
|
429 |
- } |
|
430 |
- for key := range img.Config.Volumes { |
|
431 |
- if key != "/test" { |
|
432 |
- t.Fail() |
|
433 |
- } |
|
434 |
- } |
|
435 |
-} |
|
436 |
- |
|
437 | 417 |
func TestBuildMaintainer(t *testing.T) { |
438 | 418 |
img, err := buildImage(testContextTemplate{` |
439 | 419 |
from {IMAGE} |