|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os/exec" |
| 6 | + "path/filepath" |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | +) |
| 10 | + |
| 11 | +// This is a heisen-test. Because the created timestamp of images and the behavior of |
| 12 | +// sort is not predictable it doesn't always fail. |
| 13 | +func TestBuildHistory(t *testing.T) { |
| 14 | + buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildHistory") |
| 15 | + buildCmd := exec.Command(dockerBinary, "build", "-t", "testbuildhistory", ".") |
| 16 | + |
| 17 | + buildCmd.Dir = buildDirectory |
| 18 | + out, exitCode, err := runCommandWithOutput(buildCmd) |
| 19 | + errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err)) |
| 20 | + if err != nil || exitCode != 0 { |
| 21 | + t.Fatal("failed to build the image") |
| 22 | + } |
| 23 | + |
| 24 | + out, exitCode, err = runCommandWithOutput(exec.Command(dockerBinary, "history", "testbuildhistory")) |
| 25 | + errorOut(err, t, fmt.Sprintf("image history failed: %v %v", out, err)) |
| 26 | + if err != nil || exitCode != 0 { |
| 27 | + t.Fatal("failed to get image history") |
| 28 | + } |
| 29 | + |
| 30 | + actual_values := strings.Split(out, "\n")[1:27] |
| 31 | + 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"} |
| 32 | + |
| 33 | + for i := 0; i < 26; i++ { |
| 34 | + echo_value := fmt.Sprintf("echo \"%s\"", expected_values[i]) |
| 35 | + actual_value := actual_values[i] |
| 36 | + |
| 37 | + if !strings.Contains(actual_value, echo_value) { |
| 38 | + t.Fatalf("Expected layer \"%s\", but was: %s", expected_values[i], actual_value) |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + deleteImages("testbuildhistory") |
| 43 | +} |
0 commit comments