-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpolicy_test.go
83 lines (70 loc) · 1.59 KB
/
policy_test.go
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
package gcs
import (
"testing"
)
func TestValidNewPolicy(t *testing.T) {
policy := &Policy{
Description: "test desc",
Name: "test_name",
UniqueID: "123",
Version: "1",
}
policy, err := ValidatePolicy(policy)
if err != nil {
t.Fatalf("Unable to create and validate Group: %v", err)
}
t.Logf("Name = %v", policy.Name)
}
func TestErrorInvalidNewPolicy(t *testing.T) {
policy := &Policy{
Description: "test desc",
Name: "",
UniqueID: "123",
Version: "1",
}
_, err := ValidatePolicy(policy)
if err == nil {
t.Fatalf("Validator should have flagged this as an error: %v", err)
}
}
func TestErrorValidGroupInPolicy(t *testing.T) {
policy := &Policy{
Description: "test desc",
Name: "",
UniqueID: "123",
Version: "1",
Group: &Group{Name: "test_name"},
}
_, err := ValidatePolicy(policy)
if err == nil {
t.Fatalf("Validator should have flagged this as an error: %v", err)
}
}
func TestErrorInvalidGroupInPolicy(t *testing.T) {
policy := &Policy{
Description: "test desc",
Name: "test_name",
UniqueID: "123",
Version: "1",
Group: &Group{},
}
_, err := ValidatePolicy(policy)
if err == nil {
t.Fatalf("Validator should have flagged this as an error: %v", err)
}
}
func BenchmarkPolicyValidation(b *testing.B) {
b.ReportAllocs()
policy := &Policy{
Description: "test desc",
Name: "test_name",
UniqueID: "123",
Version: "1",
}
for n := 0; n < b.N; n++ {
_, err := ValidatePolicy(policy)
if err != nil {
b.Fatalf("Policy object is invalid: %v", err)
}
}
}