Skip to content

Commit b2d4c05

Browse files
committed
cmd/coordinator: add tests for parseOutputAndBanner
For golang/go#50146. Change-Id: I44804be98159d9b1f3ba24b16c7a7fdc8fae97c5 Reviewed-on: https://go-review.googlesource.com/c/build/+/372536 Trust: Michael Pratt <[email protected]> Run-TryBot: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alex Rakoczy <[email protected]>
1 parent 1dcfe6d commit b2d4c05

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

cmd/coordinator/buildstatus_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build go1.16 && (linux || darwin)
6+
// +build go1.16
7+
// +build linux darwin
8+
9+
package main
10+
11+
import (
12+
"testing"
13+
)
14+
15+
// TestParseOutputAndBanner tests banner parsing by parseOutputAndBanner.
16+
func TestParseOutputAndBanner(t *testing.T) {
17+
for _, tc := range []struct {
18+
name string
19+
input []byte
20+
wantBanner string
21+
wantOut []byte
22+
}{
23+
{
24+
name: "standard",
25+
input: []byte(`
26+
XXXBANNERXXX:Testing packages.
27+
ok archive/tar 0.015s
28+
ok archive/zip 0.406s
29+
ok bufio 0.075s
30+
`),
31+
wantBanner: "Testing packages.",
32+
wantOut: []byte(`ok archive/tar 0.015s
33+
ok archive/zip 0.406s
34+
ok bufio 0.075s
35+
`),
36+
},
37+
{
38+
name: "banner only",
39+
input: []byte(`
40+
XXXBANNERXXX:Testing packages.
41+
`),
42+
wantBanner: "Testing packages.",
43+
wantOut: []byte(``),
44+
},
45+
{
46+
// TODO(prattmic): This is likely not desirable behavior.
47+
name: "banner only missing trailing newline",
48+
input: []byte(`
49+
XXXBANNERXXX:Testing packages.`),
50+
wantBanner: "",
51+
wantOut: []byte(`Testing packages.`),
52+
},
53+
{
54+
name: "no banner",
55+
input: []byte(`ok archive/tar 0.015s
56+
ok archive/zip 0.406s
57+
ok bufio 0.075s
58+
`),
59+
wantBanner: "",
60+
wantOut: []byte(`ok archive/tar 0.015s
61+
ok archive/zip 0.406s
62+
ok bufio 0.075s
63+
`),
64+
},
65+
{
66+
name: "no newline",
67+
input: []byte(`XXXBANNERXXX:Testing packages.
68+
ok archive/tar 0.015s
69+
ok archive/zip 0.406s
70+
ok bufio 0.075s
71+
`),
72+
wantBanner: "",
73+
wantOut: []byte(`XXXBANNERXXX:Testing packages.
74+
ok archive/tar 0.015s
75+
ok archive/zip 0.406s
76+
ok bufio 0.075s
77+
`),
78+
},
79+
{
80+
name: "wrong banner",
81+
input: []byte(`
82+
##### Testing packages.
83+
ok archive/tar 0.015s
84+
ok archive/zip 0.406s
85+
ok bufio 0.075s
86+
`),
87+
wantBanner: "",
88+
wantOut: []byte(`
89+
##### Testing packages.
90+
ok archive/tar 0.015s
91+
ok archive/zip 0.406s
92+
ok bufio 0.075s
93+
`),
94+
},
95+
} {
96+
t.Run(tc.name, func(t *testing.T) {
97+
gotBanner, gotOut := parseOutputAndBanner(tc.input)
98+
if gotBanner != tc.wantBanner {
99+
t.Errorf("parseOutputAndBanner(%q) got banner %q want banner %q", string(tc.input), gotBanner, tc.wantBanner)
100+
}
101+
if string(gotOut) != string(tc.wantOut) {
102+
t.Errorf("parseOutputAndBanner(%q) got out %q want out %q", string(tc.input), string(gotOut), string(tc.wantOut))
103+
}
104+
})
105+
}
106+
}

0 commit comments

Comments
 (0)