-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreport_list_test.go
More file actions
123 lines (118 loc) · 2.56 KB
/
report_list_test.go
File metadata and controls
123 lines (118 loc) · 2.56 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"testing"
)
func TestComparePageRe(t *testing.T) {
tests := []struct {
key string
wantStart int64
wantEnd int64
wantMatch bool
}{
{
key: "shadow-results/198000000-198000099.compare.ndjson.gz",
wantStart: 198000000,
wantEnd: 198000099,
wantMatch: true,
},
{
key: "prefix/100-199.compare.ndjson.gz",
wantStart: 100,
wantEnd: 199,
wantMatch: true,
},
{
key: "deep/nested/prefix/1-50.compare.ndjson.gz",
wantStart: 1,
wantEnd: 50,
wantMatch: true,
},
{
// Raw export page — must NOT match.
key: "shadow-results/198000000-198000099.ndjson.gz",
wantMatch: false,
},
{
// Divergence report — must NOT match.
key: "shadow-results/divergence-198032451.report.json.gz",
wantMatch: false,
},
{
// Unrelated file.
key: "shadow-results/checkpoint.json",
wantMatch: false,
},
{
// Empty key.
key: "",
wantMatch: false,
},
}
for _, tt := range tests {
t.Run(tt.key, func(t *testing.T) {
m := comparePageRe.FindStringSubmatch(tt.key)
if !tt.wantMatch {
if len(m) >= 3 {
t.Fatalf("expected no match for %q, got %v", tt.key, m)
}
return
}
if len(m) < 3 {
t.Fatalf("expected match for %q, got nil", tt.key)
}
// m[1] and m[2] parsed by strconv in the real code; verify they're numeric.
if m[1] == "" || m[2] == "" {
t.Fatalf("empty capture groups for %q", tt.key)
}
})
}
}
func TestDivergenceReportRe(t *testing.T) {
tests := []struct {
key string
wantHeight string
wantMatch bool
}{
{
key: "shadow-results/divergence-198032451.report.json.gz",
wantHeight: "198032451",
wantMatch: true,
},
{
key: "prefix/divergence-1.report.json.gz",
wantHeight: "1",
wantMatch: true,
},
{
// Comparison page — must NOT match.
key: "shadow-results/198000000-198000099.compare.ndjson.gz",
wantMatch: false,
},
{
// Raw export page — must NOT match.
key: "shadow-results/198000000-198000099.ndjson.gz",
wantMatch: false,
},
{
key: "",
wantMatch: false,
},
}
for _, tt := range tests {
t.Run(tt.key, func(t *testing.T) {
m := divergenceReportRe.FindStringSubmatch(tt.key)
if !tt.wantMatch {
if len(m) >= 2 {
t.Fatalf("expected no match for %q, got %v", tt.key, m)
}
return
}
if len(m) < 2 {
t.Fatalf("expected match for %q, got nil", tt.key)
}
if m[1] != tt.wantHeight {
t.Errorf("height = %q, want %q", m[1], tt.wantHeight)
}
})
}
}