Repository navigation
Expand file tree
/
Copy pathhost_test.go
More file actions
50 lines (45 loc) · 1.56 KB
/
Copy pathhost_test.go
File metadata and controls
50 lines (45 loc) · 1.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
package crux
import "testing"
func TestFieldsDropsOddKeyNonStringKeyAndEmptyString(t *testing.T) {
got := Fields("backend", "copilot", 7, "x", "model", "", "trigger", "governor", "dangling")
want := map[string]any{"backend": "copilot", "trigger": "governor"}
if len(got) != len(want) {
t.Fatalf("Fields = %v, want %v", got, want)
}
for k, v := range want {
if got[k] != v {
t.Errorf("Fields[%q] = %v, want %v", k, got[k], v)
}
}
}
func TestFieldsKeepsNonStringValues(t *testing.T) {
got := Fields("count", 3, "ok", true)
if got["count"] != 3 || got["ok"] != true {
t.Fatalf("Fields = %v, want count=3 ok=true", got)
}
}
func TestPRResultIsDuplicate(t *testing.T) {
cases := []struct {
name string
r PRResult
want bool
}{
{"fresh", PRResult{Number: 1}, false},
{"same head branch", PRResult{AlreadyExisted: true}, false},
{"same tree", PRResult{AlreadyExisted: true, DuplicateTree: true}, true},
{"guard redirected", PRResult{AlreadyExisted: true, DuplicateReason: "issue"}, true},
}
for _, tc := range cases {
if got := tc.r.IsDuplicate(); got != tc.want {
t.Errorf("%s: IsDuplicate = %v, want %v", tc.name, got, tc.want)
}
}
}
func TestAgentTokenCachePath(t *testing.T) {
if got, want := AgentTokenCachePath(DefaultAgentTokenCacheDir, "guide"), "/var/run/hive-metrics/agent-tokens/gh-token-guide.cache"; got != want {
t.Fatalf("AgentTokenCachePath = %q, want %q", got, want)
}
if got, want := AgentTokenCachePath("/tmp/x", "a"), "/tmp/x/gh-token-a.cache"; got != want {
t.Fatalf("AgentTokenCachePath = %q, want %q", got, want)
}
}