-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchecker_test.go
More file actions
86 lines (76 loc) · 2.14 KB
/
checker_test.go
File metadata and controls
86 lines (76 loc) · 2.14 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
// Copyright 2017-2026 Allow2 Pty Ltd. All rights reserved.
// Use of this source code is governed by the Allow2 API and SDK Licence.
package allow2service
import (
"testing"
)
func TestNormalizeActivities(t *testing.T) {
tests := []struct {
name string
input []ActivityInput
wantLen int
wantIDs []int
wantLogs []bool
}{
{
name: "single activity",
input: []ActivityInput{{ID: 1, Log: true}},
wantLen: 1,
wantIDs: []int{1},
wantLogs: []bool{true},
},
{
name: "multiple activities",
input: []ActivityInput{{ID: 1, Log: true}, {ID: 3, Log: false}, {ID: 8, Log: true}},
wantLen: 3,
wantIDs: []int{1, 3, 8},
wantLogs: []bool{true, false, true},
},
{
name: "empty",
input: []ActivityInput{},
wantLen: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := normalizeActivities(tt.input)
if len(result) != tt.wantLen {
t.Fatalf("len = %d, want %d", len(result), tt.wantLen)
}
for i, r := range result {
id, _ := r["id"].(int)
if id != tt.wantIDs[i] {
t.Errorf("result[%d][id] = %d, want %d", i, id, tt.wantIDs[i])
}
log, _ := r["log"].(bool)
if log != tt.wantLogs[i] {
t.Errorf("result[%d][log] = %v, want %v", i, log, tt.wantLogs[i])
}
}
})
}
}
func TestBuildCacheKey(t *testing.T) {
activities := normalizeActivities([]ActivityInput{
{ID: 3, Log: true},
{ID: 1, Log: true},
{ID: 8, Log: true},
})
key := buildCacheKey("user-123", activities)
// IDs should be sorted: 1, 3, 8
expected := "allow2_check_user-123_1_3_8"
if key != expected {
t.Errorf("buildCacheKey = %q, want %q", key, expected)
}
}
func TestBuildCacheKey_Deterministic(t *testing.T) {
acts1 := normalizeActivities([]ActivityInput{{ID: 3, Log: true}, {ID: 1, Log: true}})
acts2 := normalizeActivities([]ActivityInput{{ID: 1, Log: false}, {ID: 3, Log: false}})
key1 := buildCacheKey("user-1", acts1)
key2 := buildCacheKey("user-1", acts2)
// Same user, same activity IDs (regardless of log flag) => same cache key
if key1 != key2 {
t.Errorf("Cache keys should match for same user+activity IDs: %q != %q", key1, key2)
}
}