-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomain_validators_test.go
More file actions
168 lines (152 loc) · 3.79 KB
/
domain_validators_test.go
File metadata and controls
168 lines (152 loc) · 3.79 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package main
import (
"testing"
)
func TestAllPassed(t *testing.T) {
tests := []struct {
name string
results []ValidationResult
expected bool
}{
{
name: "empty results",
results: []ValidationResult{},
expected: true,
},
{
name: "all passed",
results: []ValidationResult{
{Stage: "compile", Success: true},
{Stage: "asan", Success: true},
},
expected: true,
},
{
name: "one failed",
results: []ValidationResult{
{Stage: "compile", Success: true},
{Stage: "asan", Success: false},
},
expected: false,
},
{
name: "first failed",
results: []ValidationResult{
{Stage: "compile", Success: false},
{Stage: "asan", Success: true},
},
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := allPassed(tt.results)
if result != tt.expected {
t.Errorf("allPassed() = %v, want %v", result, tt.expected)
}
})
}
}
func TestValidatorConfig(t *testing.T) {
cfg := DefaultValidatorConfig()
// Core validators should be enabled by default
if !cfg.IsEnabled(ValidatorClangTidy) {
t.Error("clang-tidy should be enabled by default")
}
if !cfg.IsEnabled(ValidatorASAN) {
t.Error("ASAN should be enabled by default")
}
// Domain validators should be disabled by default
if cfg.IsEnabled(ValidatorFrameTiming) {
t.Error("frame-timing should be disabled by default")
}
if cfg.IsEnabled(ValidatorLatency) {
t.Error("latency should be disabled by default")
}
if cfg.IsEnabled(ValidatorFuzz) {
t.Error("fuzz should be disabled by default")
}
// Test enable category
cfg.EnableCategory(CategorySecurity)
if !cfg.IsEnabled(ValidatorFuzz) {
t.Error("fuzz should be enabled after EnableCategory(security)")
}
if !cfg.IsEnabled(ValidatorSecStatic) {
t.Error("sec-static should be enabled after EnableCategory(security)")
}
// Test disable category
cfg.DisableCategory(CategorySecurity)
if cfg.IsEnabled(ValidatorFuzz) {
t.Error("fuzz should be disabled after DisableCategory(security)")
}
// Test toggle
cfg.Toggle(ValidatorLatency)
if !cfg.IsEnabled(ValidatorLatency) {
t.Error("latency should be enabled after toggle")
}
cfg.Toggle(ValidatorLatency)
if cfg.IsEnabled(ValidatorLatency) {
t.Error("latency should be disabled after second toggle")
}
}
func TestGetValidatorsByCategory(t *testing.T) {
byCategory := GetValidatorsByCategory()
// Check core validators
core := byCategory[CategoryCore]
if len(core) == 0 {
t.Error("should have core validators")
}
// Check that clang-tidy is in core
found := false
for _, v := range core {
if v.ID == ValidatorClangTidy {
found = true
break
}
}
if !found {
t.Error("clang-tidy should be in core category")
}
// Check game validators exist
game := byCategory[CategoryGame]
if len(game) != 3 {
t.Errorf("game category should have 3 validators, got %d", len(game))
}
// Check security validators exist
security := byCategory[CategorySecurity]
if len(security) != 3 {
t.Errorf("security category should have 3 validators, got %d", len(security))
}
}
func TestParseArg(t *testing.T) {
tests := []struct {
arg string
key string
expected int
wantErr bool
}{
{"max_kb=256", "max_kb", 256, false},
{"p99_us=100", "p99_us", 100, false},
{"target_fps=60", "target_fps", 60, false},
{"wrong_key=100", "max_kb", 0, true},
{"invalid", "max_kb", 0, true},
{"max_kb=notanumber", "max_kb", 0, true},
}
for _, tt := range tests {
t.Run(tt.arg, func(t *testing.T) {
result, err := parseArg(tt.arg, tt.key)
if tt.wantErr {
if err == nil {
t.Error("expected error, got nil")
}
} else {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if result != tt.expected {
t.Errorf("parseArg() = %d, want %d", result, tt.expected)
}
}
})
}
}