@@ -3,7 +3,6 @@ package main
33import (
44 "fmt"
55 "os/exec"
6- "regexp"
76 "strings"
87 "testing"
98)
@@ -85,46 +84,43 @@ func TestHistoryNonExistentImage(t *testing.T) {
8584}
8685
8786func TestHistoryImageWithComment (t * testing.T ) {
87+ name := "testhistoryimagewithcomment"
88+ defer deleteContainer (name )
89+ defer deleteImages (name )
8890
8991 // make a image through docker commit <container id> [ -m messages ]
90- runCmd := exec .Command (dockerBinary , "run" , "-i" , "-a" , "stdin" , "busybox" , "echo" , "foo" )
91- out , _ , _ , err := runCommandWithStdoutStderr (runCmd )
92+ //runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
93+ runCmd := exec .Command (dockerBinary , "run" , "--name" , name , "busybox" , "true" )
94+ out , _ , err := runCommandWithOutput (runCmd )
9295 if err != nil {
9396 t .Fatalf ("failed to run container: %s, %v" , out , err )
9497 }
9598
96- cleanedContainerID := stripTrailingCharacters (out )
97-
98- waitCmd := exec .Command (dockerBinary , "wait" , cleanedContainerID )
99- if _ , _ , err = runCommandWithOutput (waitCmd ); err != nil {
99+ waitCmd := exec .Command (dockerBinary , "wait" , name )
100+ if out , _ , err := runCommandWithOutput (waitCmd ); err != nil {
100101 t .Fatalf ("error thrown while waiting for container: %s, %v" , out , err )
101102 }
102103
103- commitCmd := exec .Command (dockerBinary , "commit" , "-m=This is a comment" , cleanedContainerID )
104- out , _ , err = runCommandWithOutput (commitCmd )
105- if err != nil {
104+ comment := "This_is_a_comment"
105+
106+ commitCmd := exec .Command (dockerBinary , "commit" , "-m=" + comment , name , name )
107+ if out , _ , err := runCommandWithOutput (commitCmd ); err != nil {
106108 t .Fatalf ("failed to commit container to image: %s, %v" , out , err )
107109 }
108110
109- cleanedImageID := stripTrailingCharacters (out )
110- deleteContainer (cleanedContainerID )
111- defer deleteImages (cleanedImageID )
112-
113111 // test docker history <image id> to check comment messages
114- historyCmd := exec .Command (dockerBinary , "history" , cleanedImageID )
112+ historyCmd := exec .Command (dockerBinary , "history" , name )
115113 out , exitCode , err := runCommandWithOutput (historyCmd )
116114 if err != nil || exitCode != 0 {
117115 t .Fatalf ("failed to get image history: %s, %v" , out , err )
118116 }
119117
120- expectedValue := "This is a comment"
121-
122- outputLine := strings .Split (out , "\n " )[1 ]
123- outputTabs := regexp .MustCompile (" +" ).Split (outputLine , - 1 )
118+ outputTabs := strings .Fields (strings .Split (out , "\n " )[1 ])
119+ //outputTabs := regexp.MustCompile(" +").Split(outputLine, -1)
124120 actualValue := outputTabs [len (outputTabs )- 1 ]
125121
126- if ! strings .Contains (actualValue , expectedValue ) {
127- t .Fatalf ("Expected comments \" %s \" , but found \" %s \" " , expectedValue , actualValue )
122+ if ! strings .Contains (actualValue , comment ) {
123+ t .Fatalf ("Expected comments %q , but found %q" , comment , actualValue )
128124 }
129125
130126 logDone ("history - history on image with comment" )
0 commit comments