Skip to content

Commit 962781d

Browse files
committed
WIP - Add test for maching VSR with VS
1 parent 6387ed4 commit 962781d

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

internal/k8s/configuration_vsr_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func TestAttemptToAddVSRtoNotExistingVS_ReturnsProblems(t *testing.T) {
186186
}
187187

188188
// TestAddVSRtoVS validates that we can add VSR to VS
189+
// todo: describe conditions and reason why the sest
189190
func TestAddVSRtoVS(t *testing.T) {
190191
t.Parallel()
191192

@@ -266,6 +267,66 @@ func TestAddVSRtoVS(t *testing.T) {
266267
func TestMatchVSwithVSRusingSelector(t *testing.T) {
267268
t.Parallel()
268269

270+
configuration := createTestConfiguration()
271+
272+
// Add VirtualServerRoute
273+
274+
labels := make(map[string]string)
275+
vsr := createTestVirtualServerRoute("virtualserverroute", "foo.example.com", "/first", labels)
276+
277+
var expectedChanges []ResourceChange
278+
expectedProblems := []ConfigurationProblem{
279+
{
280+
Object: vsr,
281+
Reason: "NoVirtualServerFound",
282+
Message: "VirtualServer is invalid or doesn't exist",
283+
},
284+
}
285+
286+
// adding VSR to the configuration; no VS exist at this stage, chance we get problems
287+
//
288+
// if we don't get it right now we call t.Fatal as there is no
289+
// point to continue the test - preconditions are not setup correctly.
290+
changes, problems := configuration.AddOrUpdateVirtualServerRoute(vsr)
291+
if !cmp.Equal(expectedChanges, changes, cmpopts.IgnoreFields(ConfigurationProblem{}, "Message")) {
292+
t.Fatal(cmp.Diff(expectedChanges, changes))
293+
}
294+
if !cmp.Equal(expectedProblems, problems, cmpopts.IgnoreFields(ConfigurationProblem{}, "Message")) {
295+
t.Fatal(cmp.Diff(expectedProblems, problems))
296+
}
297+
298+
// Add VS with VRS with the RouteSelector (LabelSelector)
299+
routes := []conf_v1.Route{
300+
{
301+
Path: "/first",
302+
Route: "virtualserverroute",
303+
},
304+
{
305+
Path: "/",
306+
RouteSelector: &metav1.LabelSelector{MatchLabels: map[string]string{"app": "route"}},
307+
},
308+
}
309+
310+
vs := createTestVirtualServerWithRoutes("virtualserver", "foo.example.com", routes)
311+
312+
expectedChanges = []ResourceChange{
313+
{
314+
Op: AddOrUpdate,
315+
Resource: &VirtualServerConfiguration{
316+
VirtualServer: vs,
317+
VirtualServerRoutes: []*conf_v1.VirtualServerRoute{vsr},
318+
},
319+
},
320+
}
321+
expectedProblems = nil
322+
323+
changes, problems = configuration.AddOrUpdateVirtualServer(vs)
324+
if !cmp.Equal(expectedChanges, changes) {
325+
t.Error(cmp.Diff(expectedChanges, changes))
326+
}
327+
if !cmp.Equal(expectedProblems, problems) {
328+
t.Error(cmp.Diff(expectedProblems, problems))
329+
}
269330
}
270331

271332
// WIP - Jakub

0 commit comments

Comments
 (0)