-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathbk_test.go
60 lines (53 loc) · 1.32 KB
/
bk_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package terminal
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestParseBuildkiteAPC(t *testing.T) {
t.Parallel()
tests := []struct {
name string
parser *parser
sequence string
wantData map[string]string
wantLastTS int64
}{
{
name: "t field",
parser: &parser{},
sequence: "bk;t=12345",
wantData: map[string]string{"t": "12345"},
wantLastTS: 12345,
},
{
name: "dt becomes t",
parser: &parser{lastTimestamp: 12345},
sequence: "bk;dt=123",
wantData: map[string]string{"t": "12468"},
wantLastTS: 12468,
},
{
name: "other field parsed",
parser: &parser{},
sequence: "bk;t=12345;p=np",
wantData: map[string]string{"t": "12345", "p": "np"},
wantLastTS: 12345,
},
}
for _, test := range tests {
test := test
t.Run(test.sequence, func(t *testing.T) {
t.Parallel()
got, err := test.parser.parseBuildkiteAPC(test.sequence)
if err != nil {
t.Fatalf("parseBuildkiteAPC(%q) error = %v", test.sequence, err)
}
if diff := cmp.Diff(got, test.wantData); diff != "" {
t.Errorf("parsed buildkite APC data diff (-got +want):\n%s", diff)
}
if got, want := test.parser.lastTimestamp, test.wantLastTS; got != want {
t.Errorf("parser.lastTimestamp = %d, want %d", got, want)
}
})
}
}