Skip to content

Commit 64cb1c1

Browse files
committed
ref(tests): adds WaitForLine and CreateVolume test helpers
1 parent c3f1eab commit 64cb1c1

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/dockercli/dockercli.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ func NewClient() (
125125
return
126126
}
127127

128+
func CreateVolume(cli *client.DockerCli, name string, path string) {
129+
RunContainer(cli,
130+
"--name", name,
131+
"-v", path,
132+
"ubuntu-debootstrap:14.04", "/bin/true")
133+
}
134+
135+
128136
// PrintToStdout prints a string to stdout.
129137
func PrintToStdout(t *testing.T, stdout *io.PipeReader,
130138
stdoutPipe *io.PipeWriter, stoptag string) string {
@@ -146,6 +154,25 @@ func PrintToStdout(t *testing.T, stdout *io.PipeReader,
146154
return result
147155
}
148156

157+
func WaitForLine(t *testing.T, stdout *io.PipeReader, stoptag string, trace bool) string {
158+
var result string
159+
r := bufio.NewReader(stdout)
160+
for {
161+
cmdBytes, err := r.ReadString('\n')
162+
if err != nil {
163+
break
164+
}
165+
result = cmdBytes
166+
if trace {
167+
fmt.Print(cmdBytes)
168+
}
169+
if strings.Contains(cmdBytes, stoptag) == true {
170+
break
171+
}
172+
}
173+
return result
174+
}
175+
149176
// GetInspectData prints and returns `docker inspect` data for a container.
150177
func GetInspectData(t *testing.T, format string, container string) string {
151178
var inspectData string

0 commit comments

Comments
 (0)