Repository navigation
Expand file tree
/
Copy pathlevels_test.go
More file actions
104 lines (93 loc) · 2.98 KB
/
Copy pathlevels_test.go
File metadata and controls
104 lines (93 loc) · 2.98 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
package redact
import "testing"
func TestAllRedactionLevels(t *testing.T) {
fixtures, err := loadLevelFixtures()
if err != nil {
t.Fatal(err)
}
levels := AllRedactionLevels()
if len(levels) != len(fixtures.ClosedSet) {
t.Fatalf("AllRedactionLevels has %d entries, want %d", len(levels), len(fixtures.ClosedSet))
}
for ordinal, want := range fixtures.ClosedSet {
got := levels[ordinal]
if got != want || !got.IsValid() || got.Ord() != ordinal {
t.Errorf("level enumeration entry %d is inconsistent", ordinal)
}
}
}
func TestAllRedactionLevels_ReturnsIndependentCopy(t *testing.T) {
fixtures, err := loadLevelFixtures()
if err != nil {
t.Fatal(err)
}
mutated := AllRedactionLevels()
mutated[0] = RedactionLevel("changed-by-caller")
mutated = append(mutated, RedactionLevel("added-by-caller"))
fresh := AllRedactionLevels()
if len(fresh) != len(fixtures.ClosedSet) {
t.Fatalf("caller mutation changed enumeration length to %d", len(fresh))
}
for ordinal, want := range fixtures.ClosedSet {
level := fresh[ordinal]
if level != want || !level.IsValid() || level.Ord() != ordinal {
t.Errorf("caller mutation changed canonical level behavior at ordinal %d", ordinal)
}
_, constructorErr := NewRedactor(level, nil, XDGPaths{})
if level == Maximum && !MaximumAvailable {
if constructorErr == nil {
t.Errorf("caller mutation bypassed Maximum refusal without cgo")
}
} else if constructorErr != nil {
t.Errorf("caller mutation made constructor reject canonical level at ordinal %d", ordinal)
}
}
if got := Max(Minimal, Standard); got != Standard {
t.Errorf("caller mutation changed Max(Minimal, Standard)")
}
if got := Max(Standard, Maximum); got != Maximum {
t.Errorf("caller mutation changed Max(Standard, Maximum)")
}
}
func TestRedactionLevel_Ord(t *testing.T) {
fixtures, err := loadLevelFixtures()
if err != nil {
t.Fatal(err)
}
for _, fixture := range fixtures.Ord {
t.Run(fixture.ID, func(t *testing.T) {
if got := fixture.Level.Ord(); got != fixture.Want {
t.Errorf("RedactionLevel(%q).Ord() = %d, want %d", fixture.Level, got, fixture.Want)
}
if got := fixture.Level.String(); got != fixture.WantString {
t.Errorf("RedactionLevel(%q).String() = %q, want %q", fixture.Level, got, fixture.WantString)
}
})
}
}
func TestRedactionLevel_Max(t *testing.T) {
fixtures, err := loadLevelFixtures()
if err != nil {
t.Fatal(err)
}
for _, fixture := range fixtures.Max {
t.Run(fixture.ID, func(t *testing.T) {
if got := Max(fixture.A, fixture.B); got != fixture.Want {
t.Errorf("Max(%q, %q) = %q, want %q", fixture.A, fixture.B, got, fixture.Want)
}
})
}
}
func TestRedactionLevel_IsValid(t *testing.T) {
fixtures, err := loadLevelFixtures()
if err != nil {
t.Fatal(err)
}
for _, fixture := range fixtures.Valid {
t.Run(fixture.ID, func(t *testing.T) {
if got := fixture.Level.IsValid(); got != fixture.Want {
t.Errorf("RedactionLevel(%q).IsValid() = %v, want %v", fixture.Level, got, fixture.Want)
}
})
}
}