Fix test logs appearing twice

This commit is contained in:
Arthur Barr
2018-03-19 17:12:04 +00:00
parent 401306b3ab
commit 913465620b

View File

@@ -24,7 +24,6 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@@ -330,7 +329,7 @@ func execContainerWithOutput(t *testing.T, cli *client.Client, ID string, user s
// Each output line has a header, which needs to be removed // Each output line has a header, which needs to be removed
_, err = stdcopy.StdCopy(buf, buf, hijack.Reader) _, err = stdcopy.StdCopy(buf, buf, hijack.Reader)
if err != nil { if err != nil {
log.Fatal(err) t.Fatal(err)
} }
return strings.TrimSpace(buf.String()) return strings.TrimSpace(buf.String())
} }
@@ -399,16 +398,15 @@ func inspectTextLogs(t *testing.T, cli *client.Client, ID string) string {
jsonLogs := inspectLogs(t, cli, ID) jsonLogs := inspectLogs(t, cli, ID)
scanner := bufio.NewScanner(strings.NewReader(jsonLogs)) scanner := bufio.NewScanner(strings.NewReader(jsonLogs))
b := make([]byte, 64*1024) b := make([]byte, 64*1024)
scanner.Buffer(b, 1024*1024)
buf := bytes.NewBuffer(b) buf := bytes.NewBuffer(b)
for scanner.Scan() { for scanner.Scan() {
t := scanner.Text() text := scanner.Text()
if strings.HasPrefix(t, "{") { if strings.HasPrefix(text, "{") {
var e map[string]interface{} var e map[string]interface{}
json.Unmarshal([]byte(scanner.Text()), &e) json.Unmarshal([]byte(text), &e)
fmt.Fprintf(buf, "{\"message\": \"%v\"}\n", e["message"]) fmt.Fprintf(buf, "{\"message\": \"%v\"}\n", e["message"])
} else { } else {
fmt.Fprintln(buf, t) fmt.Fprintln(buf, text)
} }
} }
err := scanner.Err() err := scanner.Err()
@@ -426,13 +424,13 @@ func inspectLogs(t *testing.T, cli *client.Client, ID string) string {
ShowStderr: true, ShowStderr: true,
}) })
if err != nil { if err != nil {
log.Fatal(err) t.Fatal(err)
} }
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
// Each output line has a header, which needs to be removed // Each output line has a header, which needs to be removed
_, err = stdcopy.StdCopy(buf, buf, reader) _, err = stdcopy.StdCopy(buf, buf, reader)
if err != nil { if err != nil {
log.Fatal(err) t.Fatal(err)
} }
return buf.String() return buf.String()
} }