forked from hashicorp/consul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_entry_status_test.go
187 lines (178 loc) · 5.46 KB
/
config_entry_status_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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package api
import "testing"
func TestValidateGatewayConditionReasonWithValidCombinations(t *testing.T) {
testCases := map[string]struct {
status ConditionStatus
reason GatewayConditionReason
condType GatewayConditionType
}{
"accepted": {
status: ConditionStatusTrue,
reason: GatewayReasonAccepted,
condType: GatewayConditionAccepted,
},
"accepted invalid certificates": {
status: ConditionStatusFalse,
reason: GatewayReasonInvalidCertificates,
condType: GatewayConditionAccepted,
},
"conflicted": {
status: ConditionStatusTrue,
reason: GatewayReasonRouteConflict,
condType: GatewayConditionConflicted,
},
"conflicted no conflicts": {
status: ConditionStatusFalse,
reason: GatewayReasonNoConflict,
condType: GatewayConditionConflicted,
},
"resolved refs": {
status: ConditionStatusTrue,
reason: GatewayReasonResolvedRefs,
condType: GatewayConditionResolvedRefs,
},
"resolved refs invalid certificate ref": {
status: ConditionStatusFalse,
reason: GatewayListenerReasonInvalidCertificateRef,
condType: GatewayConditionResolvedRefs,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
err := ValidateGatewayConditionReason(tc.condType, tc.status, tc.reason)
if err != nil {
t.Error("Expected gateway condition reason to be valid but it was not")
}
})
}
}
func TestValidateGatewayConditionReasonWithInvalidCombinationsReturnsError(t *testing.T) {
// This is not an exhaustive list of all invalid combinations, just a few to confirm
testCases := map[string]struct {
status ConditionStatus
reason GatewayConditionReason
condType GatewayConditionType
}{
"reason and condition type are valid but status is not": {
status: ConditionStatusTrue,
reason: GatewayReasonNoConflict,
condType: GatewayConditionConflicted,
},
"reason and status are valid but condition type is not": {
status: ConditionStatusFalse,
reason: GatewayReasonNoConflict,
condType: GatewayConditionResolvedRefs,
},
"condition type and status are valid but status is not": {
status: ConditionStatusTrue,
reason: GatewayReasonNoConflict,
condType: GatewayConditionAccepted,
},
"all are invalid": {
status: ConditionStatusUnknown,
reason: GatewayReasonAccepted,
condType: GatewayConditionResolvedRefs,
},
"pass something other than a condition status": {
status: ConditionStatus("hello"),
reason: GatewayReasonAccepted,
condType: GatewayConditionResolvedRefs,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
err := ValidateGatewayConditionReason(tc.condType, tc.status, tc.reason)
if err == nil {
t.Error("Expected route condition reason to be invalid, but it was valid")
}
})
}
}
func TestValidateRouteConfigReasonWithValidCombinations(t *testing.T) {
testCases := map[string]struct {
status ConditionStatus
reason RouteConditionReason
condType RouteConditionType
}{
"accepted all around": {
status: ConditionStatusTrue,
reason: RouteReasonAccepted,
condType: RouteConditionAccepted,
},
"accepted invalid discovery chain": {
status: ConditionStatusFalse,
reason: RouteReasonInvalidDiscoveryChain,
condType: RouteConditionAccepted,
},
"accepted no upstream services targeted": {
status: ConditionStatusFalse,
reason: RouteReasonNoUpstreamServicesTargeted,
condType: RouteConditionAccepted,
},
"route bound": {
status: ConditionStatusTrue,
reason: RouteReasonBound,
condType: RouteConditionBound,
},
"route bound gateway not found": {
status: ConditionStatusFalse,
reason: RouteReasonGatewayNotFound,
condType: RouteConditionBound,
},
"route bound failed to bind": {
status: ConditionStatusFalse,
reason: RouteReasonFailedToBind,
condType: RouteConditionBound,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
err := ValidateRouteConditionReason(tc.condType, tc.status, tc.reason)
if err != nil {
t.Errorf("Expected route condition reason to be valid, it was not")
}
})
}
}
func TestValidateRouteConditionReasonInvalidCombinationsCausePanic(t *testing.T) {
// This is not an exhaustive list of all invalid combinations, just a few to confirm
testCases := map[string]struct {
status ConditionStatus
reason RouteConditionReason
condType RouteConditionType
}{
"reason and condition type are valid but status is not": {
status: ConditionStatusTrue,
reason: RouteReasonNoUpstreamServicesTargeted,
condType: RouteConditionAccepted,
},
"reason and status are valid but condition type is not": {
status: ConditionStatusFalse,
reason: RouteReasonInvalidDiscoveryChain,
condType: RouteConditionBound,
},
"condition type and status are valid but status is not": {
status: ConditionStatusUnknown,
reason: RouteReasonBound,
condType: RouteConditionBound,
},
"all are invalid": {
status: ConditionStatusUnknown,
reason: RouteReasonGatewayNotFound,
condType: RouteConditionBound,
},
"pass something other than a condition status": {
status: ConditionStatus("hello"),
reason: RouteReasonAccepted,
condType: RouteConditionAccepted,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
err := ValidateRouteConditionReason(tc.condType, tc.status, tc.reason)
if err == nil {
t.Error("Expected route condition reason to be invalid, it was valid")
}
})
}
}