docker_cli_build_test.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. "path/filepath"
  6. "testing"
  7. )
  8. func TestBuildSixtySteps(t *testing.T) {
  9. buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildSixtySteps")
  10. buildCmd := exec.Command(dockerBinary, "build", "-t", "foobuildsixtysteps", ".")
  11. buildCmd.Dir = buildDirectory
  12. out, exitCode, err := runCommandWithOutput(buildCmd)
  13. errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
  14. if err != nil || exitCode != 0 {
  15. t.Fatal("failed to build the image")
  16. }
  17. deleteImages("foobuildsixtysteps")
  18. logDone("build - build an image with sixty build steps")
  19. }
  20. func TestAddSingleFileToRoot(t *testing.T) {
  21. buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd")
  22. buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "SingleFileToRoot")
  23. buildCmd.Dir = buildDirectory
  24. out, exitCode, err := runCommandWithOutput(buildCmd)
  25. errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
  26. if err != nil || exitCode != 0 {
  27. t.Fatal("failed to build the image")
  28. }
  29. deleteImages("testaddimg")
  30. logDone("build - add single file to root")
  31. }
  32. func TestAddSingleFileToExistDir(t *testing.T) {
  33. buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd")
  34. buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "SingleFileToExistDir")
  35. buildCmd.Dir = buildDirectory
  36. out, exitCode, err := runCommandWithOutput(buildCmd)
  37. errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
  38. if err != nil || exitCode != 0 {
  39. t.Fatal("failed to build the image")
  40. }
  41. deleteImages("testaddimg")
  42. logDone("build - add single file to existing dir")
  43. }
  44. func TestAddSingleFileToNonExistDir(t *testing.T) {
  45. buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd")
  46. buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "SingleFileToNonExistDir")
  47. buildCmd.Dir = buildDirectory
  48. out, exitCode, err := runCommandWithOutput(buildCmd)
  49. errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
  50. if err != nil || exitCode != 0 {
  51. t.Fatal("failed to build the image")
  52. }
  53. deleteImages("testaddimg")
  54. logDone("build - add single file to non-existing dir")
  55. }
  56. func TestAddDirContentToRoot(t *testing.T) {
  57. buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd")
  58. buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "DirContentToRoot")
  59. buildCmd.Dir = buildDirectory
  60. out, exitCode, err := runCommandWithOutput(buildCmd)
  61. errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
  62. if err != nil || exitCode != 0 {
  63. t.Fatal("failed to build the image")
  64. }
  65. deleteImages("testaddimg")
  66. logDone("build - add directory contents to root")
  67. }
  68. func TestAddDirContentToExistDir(t *testing.T) {
  69. buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd")
  70. buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "DirContentToExistDir")
  71. buildCmd.Dir = buildDirectory
  72. out, exitCode, err := runCommandWithOutput(buildCmd)
  73. errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
  74. if err != nil || exitCode != 0 {
  75. t.Fatal("failed to build the image")
  76. }
  77. deleteImages("testaddimg")
  78. logDone("build - add directory contents to existing dir")
  79. }
  80. func TestAddWholeDirToRoot(t *testing.T) {
  81. buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd")
  82. buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "WholeDirToRoot")
  83. buildCmd.Dir = buildDirectory
  84. out, exitCode, err := runCommandWithOutput(buildCmd)
  85. errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
  86. if err != nil || exitCode != 0 {
  87. t.Fatal("failed to build the image")
  88. }
  89. deleteImages("testaddimg")
  90. logDone("build - add whole directory to root")
  91. }
  92. // TODO: TestCaching
  93. // TODO: TestADDCacheInvalidation