2014-05-02 15:16:46 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-05-02 15:16:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// This is a heisen-test. Because the created timestamp of images and the behavior of
|
|
|
|
// sort is not predictable it doesn't always fail.
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestBuildHistory(c *check.C) {
|
2014-09-24 04:38:48 -04:00
|
|
|
name := "testbuildhistory"
|
|
|
|
defer deleteImages(name)
|
|
|
|
_, err := buildImage(name, `FROM busybox
|
|
|
|
RUN echo "A"
|
|
|
|
RUN echo "B"
|
|
|
|
RUN echo "C"
|
|
|
|
RUN echo "D"
|
|
|
|
RUN echo "E"
|
|
|
|
RUN echo "F"
|
|
|
|
RUN echo "G"
|
|
|
|
RUN echo "H"
|
|
|
|
RUN echo "I"
|
|
|
|
RUN echo "J"
|
|
|
|
RUN echo "K"
|
|
|
|
RUN echo "L"
|
|
|
|
RUN echo "M"
|
|
|
|
RUN echo "N"
|
|
|
|
RUN echo "O"
|
|
|
|
RUN echo "P"
|
|
|
|
RUN echo "Q"
|
|
|
|
RUN echo "R"
|
|
|
|
RUN echo "S"
|
|
|
|
RUN echo "T"
|
|
|
|
RUN echo "U"
|
|
|
|
RUN echo "V"
|
|
|
|
RUN echo "W"
|
|
|
|
RUN echo "X"
|
|
|
|
RUN echo "Y"
|
|
|
|
RUN echo "Z"`,
|
|
|
|
true)
|
2014-05-02 15:16:46 -04:00
|
|
|
|
2014-09-24 04:38:48 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-05-02 15:16:46 -04:00
|
|
|
}
|
|
|
|
|
2014-09-24 04:38:48 -04:00
|
|
|
out, exitCode, err := runCommandWithOutput(exec.Command(dockerBinary, "history", "testbuildhistory"))
|
2014-05-02 15:16:46 -04:00
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to get image history: %s, %v", out, err)
|
2014-05-02 15:16:46 -04:00
|
|
|
}
|
|
|
|
|
2014-10-06 10:26:55 -04:00
|
|
|
actualValues := strings.Split(out, "\n")[1:27]
|
|
|
|
expectedValues := [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"}
|
2014-05-02 15:16:46 -04:00
|
|
|
|
|
|
|
for i := 0; i < 26; i++ {
|
2014-10-06 10:26:55 -04:00
|
|
|
echoValue := fmt.Sprintf("echo \"%s\"", expectedValues[i])
|
|
|
|
actualValue := actualValues[i]
|
2014-05-02 15:16:46 -04:00
|
|
|
|
2014-10-06 10:26:55 -04:00
|
|
|
if !strings.Contains(actualValue, echoValue) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected layer \"%s\", but was: %s", expectedValues[i], actualValue)
|
2014-05-02 15:16:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-06-29 19:31:16 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestHistoryExistentImage(c *check.C) {
|
2014-06-29 19:31:16 -04:00
|
|
|
historyCmd := exec.Command(dockerBinary, "history", "busybox")
|
|
|
|
_, exitCode, err := runCommandWithOutput(historyCmd)
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("failed to get image history")
|
2014-06-29 19:31:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) {
|
2014-06-29 19:31:16 -04:00
|
|
|
historyCmd := exec.Command(dockerBinary, "history", "testHistoryNonExistentImage")
|
|
|
|
_, exitCode, err := runCommandWithOutput(historyCmd)
|
|
|
|
if err == nil || exitCode == 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("history on a non-existent image didn't result in a non-zero exit status")
|
2014-06-29 19:31:16 -04:00
|
|
|
}
|
|
|
|
}
|
2015-01-04 01:47:01 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) {
|
2015-04-08 19:43:25 -04:00
|
|
|
name := "testhistoryimagewithcomment"
|
|
|
|
defer deleteContainer(name)
|
|
|
|
defer deleteImages(name)
|
2015-01-04 01:47:01 -05:00
|
|
|
|
|
|
|
// make a image through docker commit <container id> [ -m messages ]
|
2015-04-08 19:43:25 -04:00
|
|
|
//runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2015-01-04 01:47:01 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to run container: %s, %v", out, err)
|
2015-01-04 01:47:01 -05:00
|
|
|
}
|
|
|
|
|
2015-04-08 19:43:25 -04:00
|
|
|
waitCmd := exec.Command(dockerBinary, "wait", name)
|
|
|
|
if out, _, err := runCommandWithOutput(waitCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
|
2015-01-04 01:47:01 -05:00
|
|
|
}
|
|
|
|
|
2015-04-08 19:43:25 -04:00
|
|
|
comment := "This_is_a_comment"
|
|
|
|
|
|
|
|
commitCmd := exec.Command(dockerBinary, "commit", "-m="+comment, name, name)
|
|
|
|
if out, _, err := runCommandWithOutput(commitCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to commit container to image: %s, %v", out, err)
|
2015-01-04 01:47:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// test docker history <image id> to check comment messages
|
2015-04-08 19:43:25 -04:00
|
|
|
historyCmd := exec.Command(dockerBinary, "history", name)
|
2015-01-04 01:47:01 -05:00
|
|
|
out, exitCode, err := runCommandWithOutput(historyCmd)
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to get image history: %s, %v", out, err)
|
2015-01-04 01:47:01 -05:00
|
|
|
}
|
|
|
|
|
2015-04-08 19:43:25 -04:00
|
|
|
outputTabs := strings.Fields(strings.Split(out, "\n")[1])
|
|
|
|
//outputTabs := regexp.MustCompile(" +").Split(outputLine, -1)
|
2015-01-04 01:47:01 -05:00
|
|
|
actualValue := outputTabs[len(outputTabs)-1]
|
|
|
|
|
2015-04-08 19:43:25 -04:00
|
|
|
if !strings.Contains(actualValue, comment) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected comments %q, but found %q", comment, actualValue)
|
2015-01-04 01:47:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|