integration cli: minor refactor of the build tests
| ... | ... |
@@ -15,24 +15,28 @@ import ( |
| 15 | 15 |
) |
| 16 | 16 |
|
| 17 | 17 |
func TestBuildCacheADD(t *testing.T) {
|
| 18 |
- buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1") |
|
| 19 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testcacheadd1", ".") |
|
| 20 |
- buildCmd.Dir = buildDirectory |
|
| 21 |
- exitCode, err := runCommand(buildCmd) |
|
| 22 |
- errorOut(err, t, fmt.Sprintf("build failed to complete: %v", err))
|
|
| 18 |
+ var ( |
|
| 19 |
+ exitCode int |
|
| 20 |
+ out string |
|
| 21 |
+ err error |
|
| 22 |
+ ) |
|
| 23 |
+ {
|
|
| 24 |
+ buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1") |
|
| 25 |
+ out, exitCode, err = dockerCmdInDir(t, buildDirectory, "build", "-t", "testcacheadd1", ".") |
|
| 26 |
+ errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
|
| 23 | 27 |
|
| 24 |
- if err != nil || exitCode != 0 {
|
|
| 25 |
- t.Fatal("failed to build the image")
|
|
| 28 |
+ if err != nil || exitCode != 0 {
|
|
| 29 |
+ t.Fatal("failed to build the image")
|
|
| 30 |
+ } |
|
| 26 | 31 |
} |
| 32 |
+ {
|
|
| 33 |
+ buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "2") |
|
| 34 |
+ out, exitCode, err = dockerCmdInDir(t, buildDirectory, "build", "-t", "testcacheadd2", ".") |
|
| 35 |
+ errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
|
| 27 | 36 |
|
| 28 |
- buildDirectory = filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "2") |
|
| 29 |
- buildCmd = exec.Command(dockerBinary, "build", "-t", "testcacheadd2", ".") |
|
| 30 |
- buildCmd.Dir = buildDirectory |
|
| 31 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 32 |
- errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
|
| 33 |
- |
|
| 34 |
- if err != nil || exitCode != 0 {
|
|
| 35 |
- t.Fatal("failed to build the image")
|
|
| 37 |
+ if err != nil || exitCode != 0 {
|
|
| 38 |
+ t.Fatal("failed to build the image")
|
|
| 39 |
+ } |
|
| 36 | 40 |
} |
| 37 | 41 |
|
| 38 | 42 |
if strings.Contains(out, "Using cache") {
|
| ... | ... |
@@ -47,9 +51,7 @@ func TestBuildCacheADD(t *testing.T) {
|
| 47 | 47 |
|
| 48 | 48 |
func TestBuildSixtySteps(t *testing.T) {
|
| 49 | 49 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildSixtySteps") |
| 50 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "foobuildsixtysteps", ".") |
|
| 51 |
- buildCmd.Dir = buildDirectory |
|
| 52 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 50 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "foobuildsixtysteps", ".") |
|
| 53 | 51 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 54 | 52 |
|
| 55 | 53 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -68,9 +70,7 @@ func TestAddSingleFileToRoot(t *testing.T) {
|
| 68 | 68 |
t.Fatal(err) |
| 69 | 69 |
} |
| 70 | 70 |
f.Close() |
| 71 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", ".") |
|
| 72 |
- buildCmd.Dir = buildDirectory |
|
| 73 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 71 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", ".") |
|
| 74 | 72 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 75 | 73 |
|
| 76 | 74 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -120,9 +120,7 @@ func TestAddSingleFileToWorkdir(t *testing.T) {
|
| 120 | 120 |
|
| 121 | 121 |
func TestAddSingleFileToExistDir(t *testing.T) {
|
| 122 | 122 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd") |
| 123 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "SingleFileToExistDir") |
|
| 124 |
- buildCmd.Dir = buildDirectory |
|
| 125 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 123 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", "SingleFileToExistDir") |
|
| 126 | 124 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 127 | 125 |
|
| 128 | 126 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -136,9 +134,7 @@ func TestAddSingleFileToExistDir(t *testing.T) {
|
| 136 | 136 |
|
| 137 | 137 |
func TestAddSingleFileToNonExistDir(t *testing.T) {
|
| 138 | 138 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd") |
| 139 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "SingleFileToNonExistDir") |
|
| 140 |
- buildCmd.Dir = buildDirectory |
|
| 141 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 139 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", "SingleFileToNonExistDir") |
|
| 142 | 140 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 143 | 141 |
|
| 144 | 142 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -152,9 +148,7 @@ func TestAddSingleFileToNonExistDir(t *testing.T) {
|
| 152 | 152 |
|
| 153 | 153 |
func TestAddDirContentToRoot(t *testing.T) {
|
| 154 | 154 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd") |
| 155 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "DirContentToRoot") |
|
| 156 |
- buildCmd.Dir = buildDirectory |
|
| 157 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 155 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", "DirContentToRoot") |
|
| 158 | 156 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 159 | 157 |
|
| 160 | 158 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -168,9 +162,7 @@ func TestAddDirContentToRoot(t *testing.T) {
|
| 168 | 168 |
|
| 169 | 169 |
func TestAddDirContentToExistDir(t *testing.T) {
|
| 170 | 170 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd") |
| 171 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "DirContentToExistDir") |
|
| 172 |
- buildCmd.Dir = buildDirectory |
|
| 173 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 171 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", "DirContentToExistDir") |
|
| 174 | 172 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 175 | 173 |
|
| 176 | 174 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -193,9 +185,7 @@ func TestAddWholeDirToRoot(t *testing.T) {
|
| 193 | 193 |
t.Fatal(err) |
| 194 | 194 |
} |
| 195 | 195 |
f.Close() |
| 196 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", ".") |
|
| 197 |
- buildCmd.Dir = buildDirectory |
|
| 198 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 196 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", ".") |
|
| 199 | 197 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 200 | 198 |
|
| 201 | 199 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -209,9 +199,7 @@ func TestAddWholeDirToRoot(t *testing.T) {
|
| 209 | 209 |
|
| 210 | 210 |
func TestAddEtcToRoot(t *testing.T) {
|
| 211 | 211 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd") |
| 212 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "EtcToRoot") |
|
| 213 |
- buildCmd.Dir = buildDirectory |
|
| 214 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 212 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", "EtcToRoot") |
|
| 215 | 213 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 216 | 214 |
|
| 217 | 215 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -229,9 +217,7 @@ func TestCopySingleFileToRoot(t *testing.T) {
|
| 229 | 229 |
t.Fatal(err) |
| 230 | 230 |
} |
| 231 | 231 |
f.Close() |
| 232 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testcopyimg", ".") |
|
| 233 |
- buildCmd.Dir = buildDirectory |
|
| 234 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 232 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", ".") |
|
| 235 | 233 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 236 | 234 |
|
| 237 | 235 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -281,9 +267,7 @@ func TestCopySingleFileToWorkdir(t *testing.T) {
|
| 281 | 281 |
|
| 282 | 282 |
func TestCopySingleFileToExistDir(t *testing.T) {
|
| 283 | 283 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") |
| 284 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testcopyimg", "SingleFileToExistDir") |
|
| 285 |
- buildCmd.Dir = buildDirectory |
|
| 286 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 284 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "SingleFileToExistDir") |
|
| 287 | 285 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 288 | 286 |
|
| 289 | 287 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -297,9 +281,7 @@ func TestCopySingleFileToExistDir(t *testing.T) {
|
| 297 | 297 |
|
| 298 | 298 |
func TestCopySingleFileToNonExistDir(t *testing.T) {
|
| 299 | 299 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") |
| 300 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testcopyimg", "SingleFileToNonExistDir") |
|
| 301 |
- buildCmd.Dir = buildDirectory |
|
| 302 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 300 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "SingleFileToNonExistDir") |
|
| 303 | 301 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 304 | 302 |
|
| 305 | 303 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -313,9 +295,7 @@ func TestCopySingleFileToNonExistDir(t *testing.T) {
|
| 313 | 313 |
|
| 314 | 314 |
func TestCopyDirContentToRoot(t *testing.T) {
|
| 315 | 315 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") |
| 316 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testcopyimg", "DirContentToRoot") |
|
| 317 |
- buildCmd.Dir = buildDirectory |
|
| 318 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 316 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "DirContentToRoot") |
|
| 319 | 317 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 320 | 318 |
|
| 321 | 319 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -329,9 +309,7 @@ func TestCopyDirContentToRoot(t *testing.T) {
|
| 329 | 329 |
|
| 330 | 330 |
func TestCopyDirContentToExistDir(t *testing.T) {
|
| 331 | 331 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") |
| 332 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testcopyimg", "DirContentToExistDir") |
|
| 333 |
- buildCmd.Dir = buildDirectory |
|
| 334 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 332 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "DirContentToExistDir") |
|
| 335 | 333 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 336 | 334 |
|
| 337 | 335 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -354,9 +332,7 @@ func TestCopyWholeDirToRoot(t *testing.T) {
|
| 354 | 354 |
t.Fatal(err) |
| 355 | 355 |
} |
| 356 | 356 |
f.Close() |
| 357 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testcopyimg", ".") |
|
| 358 |
- buildCmd.Dir = buildDirectory |
|
| 359 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 357 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", ".") |
|
| 360 | 358 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 361 | 359 |
|
| 362 | 360 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -370,9 +346,7 @@ func TestCopyWholeDirToRoot(t *testing.T) {
|
| 370 | 370 |
|
| 371 | 371 |
func TestCopyEtcToRoot(t *testing.T) {
|
| 372 | 372 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") |
| 373 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testcopyimg", "EtcToRoot") |
|
| 374 |
- buildCmd.Dir = buildDirectory |
|
| 375 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 373 |
+ out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "EtcToRoot") |
|
| 376 | 374 |
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
| 377 | 375 |
|
| 378 | 376 |
if err != nil || exitCode != 0 {
|
| ... | ... |
@@ -465,9 +439,7 @@ func TestBuildWithInaccessibleFilesInContext(t *testing.T) {
|
| 465 | 465 |
// This test doesn't require that we run commands as an unprivileged user |
| 466 | 466 |
pathToDirectoryWhichContainsLinks := filepath.Join(buildDirectory, "linksdirectory") |
| 467 | 467 |
|
| 468 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testlinksok", ".") |
|
| 469 |
- buildCmd.Dir = pathToDirectoryWhichContainsLinks |
|
| 470 |
- out, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 468 |
+ out, exitCode, err := dockerCmdInDir(t, pathToDirectoryWhichContainsLinks, "build", "-t", "testlinksok", ".") |
|
| 471 | 469 |
if err != nil || exitCode != 0 {
|
| 472 | 470 |
t.Fatalf("build should have worked: %s %s", err, out)
|
| 473 | 471 |
} |
| ... | ... |
@@ -538,9 +510,7 @@ func TestBuildRm(t *testing.T) {
|
| 538 | 538 |
} |
| 539 | 539 |
|
| 540 | 540 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm") |
| 541 |
- buildCmd := exec.Command(dockerBinary, "build", "--rm", "-t", "testbuildrm", ".") |
|
| 542 |
- buildCmd.Dir = buildDirectory |
|
| 543 |
- _, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 541 |
+ _, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "--rm", "-t", "testbuildrm", ".") |
|
| 544 | 542 |
|
| 545 | 543 |
if err != nil || exitCode != 0 {
|
| 546 | 544 |
t.Fatal("failed to build the image")
|
| ... | ... |
@@ -564,9 +534,7 @@ func TestBuildRm(t *testing.T) {
|
| 564 | 564 |
} |
| 565 | 565 |
|
| 566 | 566 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm") |
| 567 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", "testbuildrm", ".") |
|
| 568 |
- buildCmd.Dir = buildDirectory |
|
| 569 |
- _, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 567 |
+ _, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testbuildrm", ".") |
|
| 570 | 568 |
|
| 571 | 569 |
if err != nil || exitCode != 0 {
|
| 572 | 570 |
t.Fatal("failed to build the image")
|
| ... | ... |
@@ -590,9 +558,7 @@ func TestBuildRm(t *testing.T) {
|
| 590 | 590 |
} |
| 591 | 591 |
|
| 592 | 592 |
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm") |
| 593 |
- buildCmd := exec.Command(dockerBinary, "build", "--rm=false", "-t", "testbuildrm", ".") |
|
| 594 |
- buildCmd.Dir = buildDirectory |
|
| 595 |
- _, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 593 |
+ _, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "--rm=false", "-t", "testbuildrm", ".") |
|
| 596 | 594 |
|
| 597 | 595 |
if err != nil || exitCode != 0 {
|
| 598 | 596 |
t.Fatal("failed to build the image")
|
| ... | ... |
@@ -808,52 +774,53 @@ func TestBuildEntrypoint(t *testing.T) {
|
| 808 | 808 |
|
| 809 | 809 |
// #6445 ensure ONBUILD triggers aren't committed to grandchildren |
| 810 | 810 |
func TestBuildOnBuildLimitedInheritence(t *testing.T) {
|
| 811 |
- name1 := "testonbuildtrigger1" |
|
| 812 |
- dockerfile1 := ` |
|
| 811 |
+ var ( |
|
| 812 |
+ out2, out3 string |
|
| 813 |
+ ) |
|
| 814 |
+ {
|
|
| 815 |
+ name1 := "testonbuildtrigger1" |
|
| 816 |
+ dockerfile1 := ` |
|
| 813 | 817 |
FROM busybox |
| 814 | 818 |
RUN echo "GRANDPARENT" |
| 815 | 819 |
ONBUILD RUN echo "ONBUILD PARENT" |
| 816 |
- ` |
|
| 817 |
- ctx1, err := fakeContext(dockerfile1, nil) |
|
| 818 |
- if err != nil {
|
|
| 819 |
- t.Fatal(err) |
|
| 820 |
- } |
|
| 821 |
- |
|
| 822 |
- buildCmd := exec.Command(dockerBinary, "build", "-t", name1, ".") |
|
| 823 |
- buildCmd.Dir = ctx1.Dir |
|
| 824 |
- out1, _, err := runCommandWithOutput(buildCmd) |
|
| 825 |
- errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out1, err))
|
|
| 826 |
- defer deleteImages(name1) |
|
| 820 |
+ ` |
|
| 821 |
+ ctx, err := fakeContext(dockerfile1, nil) |
|
| 822 |
+ if err != nil {
|
|
| 823 |
+ t.Fatal(err) |
|
| 824 |
+ } |
|
| 827 | 825 |
|
| 828 |
- name2 := "testonbuildtrigger2" |
|
| 829 |
- dockerfile2 := ` |
|
| 830 |
- FROM testonbuildtrigger1 |
|
| 831 |
- ` |
|
| 832 |
- ctx2, err := fakeContext(dockerfile2, nil) |
|
| 833 |
- if err != nil {
|
|
| 834 |
- t.Fatal(err) |
|
| 826 |
+ out1, _, err := dockerCmdInDir(t, ctx.Dir, "build", "-t", name1, ".") |
|
| 827 |
+ errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out1, err))
|
|
| 828 |
+ defer deleteImages(name1) |
|
| 835 | 829 |
} |
| 830 |
+ {
|
|
| 831 |
+ name2 := "testonbuildtrigger2" |
|
| 832 |
+ dockerfile2 := ` |
|
| 833 |
+ FROM testonbuildtrigger1 |
|
| 834 |
+ ` |
|
| 835 |
+ ctx, err := fakeContext(dockerfile2, nil) |
|
| 836 |
+ if err != nil {
|
|
| 837 |
+ t.Fatal(err) |
|
| 838 |
+ } |
|
| 836 | 839 |
|
| 837 |
- buildCmd = exec.Command(dockerBinary, "build", "-t", name2, ".") |
|
| 838 |
- buildCmd.Dir = ctx2.Dir |
|
| 839 |
- out2, _, err := runCommandWithOutput(buildCmd) |
|
| 840 |
- errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out2, err))
|
|
| 841 |
- defer deleteImages(name2) |
|
| 842 |
- |
|
| 843 |
- name3 := "testonbuildtrigger3" |
|
| 844 |
- dockerfile3 := ` |
|
| 845 |
- FROM testonbuildtrigger2 |
|
| 846 |
- ` |
|
| 847 |
- ctx3, err := fakeContext(dockerfile3, nil) |
|
| 848 |
- if err != nil {
|
|
| 849 |
- t.Fatal(err) |
|
| 840 |
+ out2, _, err = dockerCmdInDir(t, ctx.Dir, "build", "-t", name2, ".") |
|
| 841 |
+ errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out2, err))
|
|
| 842 |
+ defer deleteImages(name2) |
|
| 850 | 843 |
} |
| 844 |
+ {
|
|
| 845 |
+ name3 := "testonbuildtrigger3" |
|
| 846 |
+ dockerfile3 := ` |
|
| 847 |
+ FROM testonbuildtrigger2 |
|
| 848 |
+ ` |
|
| 849 |
+ ctx, err := fakeContext(dockerfile3, nil) |
|
| 850 |
+ if err != nil {
|
|
| 851 |
+ t.Fatal(err) |
|
| 852 |
+ } |
|
| 851 | 853 |
|
| 852 |
- buildCmd = exec.Command(dockerBinary, "build", "-t", name3, ".") |
|
| 853 |
- buildCmd.Dir = ctx3.Dir |
|
| 854 |
- out3, _, err := runCommandWithOutput(buildCmd) |
|
| 855 |
- errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out3, err))
|
|
| 856 |
- defer deleteImages(name3) |
|
| 854 |
+ out3, _, err = dockerCmdInDir(t, ctx.Dir, "build", "-t", name3, ".") |
|
| 855 |
+ errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out3, err))
|
|
| 856 |
+ defer deleteImages(name3) |
|
| 857 |
+ } |
|
| 857 | 858 |
|
| 858 | 859 |
// ONBUILD should be run in second build. |
| 859 | 860 |
if !strings.Contains(out2, "ONBUILD PARENT") {
|
| ... | ... |
@@ -88,12 +88,26 @@ func pullImageIfNotExist(image string) (err error) {
|
| 88 | 88 |
return |
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 |
+// deprecated, use dockerCmd instead |
|
| 91 | 92 |
func cmd(t *testing.T, args ...string) (string, int, error) {
|
| 93 |
+ return dockerCmd(t, args...) |
|
| 94 |
+} |
|
| 95 |
+ |
|
| 96 |
+func dockerCmd(t *testing.T, args ...string) (string, int, error) {
|
|
| 92 | 97 |
out, status, err := runCommandWithOutput(exec.Command(dockerBinary, args...)) |
| 93 | 98 |
errorOut(err, t, fmt.Sprintf("'%s' failed with errors: %v (%v)", strings.Join(args, " "), err, out))
|
| 94 | 99 |
return out, status, err |
| 95 | 100 |
} |
| 96 | 101 |
|
| 102 |
+// execute a docker command in a directory |
|
| 103 |
+func dockerCmdInDir(t *testing.T, path string, args ...string) (string, int, error) {
|
|
| 104 |
+ dockerCommand := exec.Command(dockerBinary, args...) |
|
| 105 |
+ dockerCommand.Dir = path |
|
| 106 |
+ out, status, err := runCommandWithOutput(dockerCommand) |
|
| 107 |
+ errorOut(err, t, fmt.Sprintf("'%s' failed with errors: %v (%v)", strings.Join(args, " "), err, out))
|
|
| 108 |
+ return out, status, err |
|
| 109 |
+} |
|
| 110 |
+ |
|
| 97 | 111 |
func findContainerIp(t *testing.T, id string) string {
|
| 98 | 112 |
cmd := exec.Command(dockerBinary, "inspect", "--format='{{ .NetworkSettings.IPAddress }}'", id)
|
| 99 | 113 |
out, _, err := runCommandWithOutput(cmd) |