docker_cli_history_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. "path/filepath"
  6. "strings"
  7. "testing"
  8. )
  9. // This is a heisen-test. Because the created timestamp of images and the behavior of
  10. // sort is not predictable it doesn't always fail.
  11. func TestBuildHistory(t *testing.T) {
  12. buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildHistory")
  13. buildCmd := exec.Command(dockerBinary, "build", "-t", "testbuildhistory", ".")
  14. buildCmd.Dir = buildDirectory
  15. out, exitCode, err := runCommandWithOutput(buildCmd)
  16. errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
  17. if err != nil || exitCode != 0 {
  18. t.Fatal("failed to build the image")
  19. }
  20. out, exitCode, err = runCommandWithOutput(exec.Command(dockerBinary, "history", "testbuildhistory"))
  21. errorOut(err, t, fmt.Sprintf("image history failed: %v %v", out, err))
  22. if err != nil || exitCode != 0 {
  23. t.Fatal("failed to get image history")
  24. }
  25. actual_values := strings.Split(out, "\n")[1:27]
  26. expected_values := [26]string{"Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"}
  27. for i := 0; i < 26; i++ {
  28. echo_value := fmt.Sprintf("echo \"%s\"", expected_values[i])
  29. actual_value := actual_values[i]
  30. if !strings.Contains(actual_value, echo_value) {
  31. t.Fatalf("Expected layer \"%s\", but was: %s", expected_values[i], actual_value)
  32. }
  33. }
  34. deleteImages("testbuildhistory")
  35. }