Skip to content

Commit d803523

Browse files
author
Michael Crosby
committedJun 18, 2014
Merge pull request moby#5559 from bmurphy1976/bmurphy1976-history-bug
Test and fix history command ordering
2 parents 443d923 + e827c8f commit d803523

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM busybox
2+
3+
RUN echo "A"
4+
RUN echo "B"
5+
RUN echo "C"
6+
RUN echo "D"
7+
RUN echo "E"
8+
RUN echo "F"
9+
RUN echo "G"
10+
RUN echo "H"
11+
RUN echo "I"
12+
RUN echo "J"
13+
RUN echo "K"
14+
RUN echo "L"
15+
RUN echo "M"
16+
RUN echo "N"
17+
RUN echo "O"
18+
RUN echo "P"
19+
RUN echo "Q"
20+
RUN echo "R"
21+
RUN echo "S"
22+
RUN echo "T"
23+
RUN echo "U"
24+
RUN echo "V"
25+
RUN echo "W"
26+
RUN echo "X"
27+
RUN echo "Y"
28+
RUN echo "Z"
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

‎server/server.go

-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,6 @@ func (srv *Server) ImageHistory(job *engine.Job) engine.Status {
818818
outs.Add(out)
819819
return nil
820820
})
821-
outs.ReverseSort()
822821
if _, err := outs.WriteListTo(job.Stdout); err != nil {
823822
return job.Error(err)
824823
}

0 commit comments

Comments
 (0)