forked from rbaliyan/config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamespace_test.go
More file actions
49 lines (44 loc) · 1.1 KB
/
namespace_test.go
File metadata and controls
49 lines (44 loc) · 1.1 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
package config
import "testing"
func TestIsSystemNamespace(t *testing.T) {
tests := []struct {
namespace string
want bool
}{
{"internal:config:crypto", true},
{"internal:", true},
{"internal:anything", true},
{"production", false},
{"", false},
{"internal", false},
{"INTERNAL:", false},
{"Internal:", false},
{"xinternal:", false},
}
for _, tt := range tests {
t.Run(tt.namespace, func(t *testing.T) {
got := IsSystemNamespace(tt.namespace)
if got != tt.want {
t.Errorf("IsSystemNamespace(%q) = %v, want %v", tt.namespace, got, tt.want)
}
})
}
}
func TestSystemNamespacePassesValidation(t *testing.T) {
// System namespaces like "internal:config:crypto" must be valid namespaces.
namespaces := []string{
"internal:config:crypto",
"internal:keys",
"internal:discovery",
}
for _, ns := range namespaces {
t.Run(ns, func(t *testing.T) {
if err := ValidateNamespace(ns); err != nil {
t.Errorf("ValidateNamespace(%q) = %v, want nil", ns, err)
}
if !IsSystemNamespace(ns) {
t.Errorf("IsSystemNamespace(%q) = false, want true", ns)
}
})
}
}