Skip to content

Commit 83f508d

Browse files
committed
WIP - Add VSR to VS
1 parent 83df813 commit 83f508d

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

internal/k8s/configuration_vsr_test.go

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

188+
// TestAddVSRtoVS logic:
189+
//
190+
// 1) Create VSR
191+
// 2) Create VS
192+
// 3) Add the VSR to the VS
193+
func TestAddVSRtoVS(t *testing.T) {
194+
t.Parallel()
195+
196+
configuration := createTestConfiguration()
197+
198+
// =========
199+
// Step 1
200+
// =========
201+
// Add VirtualServerRoute
202+
// We add VSR that references not existing VS. Chance we expect to see `Problems`
203+
204+
labels := make(map[string]string)
205+
vsr := createTestVirtualServerRoute("virtualserverroute", "foo.example.com", "/first", labels)
206+
207+
var expectedChanges []ResourceChange
208+
expectedProblems := []ConfigurationProblem{
209+
{
210+
Object: vsr,
211+
Reason: "NoVirtualServerFound",
212+
Message: "VirtualServer is invalid or doesn't exist",
213+
},
214+
}
215+
216+
// adding VSR but no VS exist at this stage, chance we get problems
217+
// if we don't get it right now we call t.Fatal as there is no
218+
// point to continue test - preconditions are not setup correctly.
219+
changes, problems := configuration.AddOrUpdateVirtualServerRoute(vsr)
220+
if !cmp.Equal(expectedChanges, changes, cmpopts.IgnoreFields(ConfigurationProblem{}, "Message")) {
221+
t.Fatal(cmp.Diff(expectedChanges, changes))
222+
}
223+
if !cmp.Equal(expectedProblems, problems, cmpopts.IgnoreFields(ConfigurationProblem{}, "Message")) {
224+
t.Fatal(cmp.Diff(expectedProblems, problems))
225+
}
226+
227+
// =========
228+
// Step 2
229+
// =========
230+
// Create the missing VS with routes.
231+
// Note that the 1st Route in the routes slice below matches the route from the previous step!
232+
233+
routes := []conf_v1.Route{
234+
{
235+
Path: "/first",
236+
Route: "virtualserverroute",
237+
},
238+
{
239+
Path: "/",
240+
RouteSelector: &metav1.LabelSelector{MatchLabels: map[string]string{"app": "route"}},
241+
},
242+
}
243+
244+
vs := createTestVirtualServerWithRoutes("virtualserver", "foo.example.com", routes)
245+
246+
expectedChanges = []ResourceChange{
247+
{
248+
Op: AddOrUpdate,
249+
Resource: &VirtualServerConfiguration{
250+
VirtualServer: vs,
251+
VirtualServerRoutes: []*conf_v1.VirtualServerRoute{vsr},
252+
},
253+
},
254+
}
255+
expectedProblems = nil
256+
257+
// We update configuration here - add the missing VS (see Step 1)
258+
// At this point we have both VS and VSR in the configuration. They match.
259+
changes, problems = configuration.AddOrUpdateVirtualServer(vs)
260+
261+
if !cmp.Equal(expectedChanges, changes) {
262+
t.Error(cmp.Diff(expectedChanges, changes))
263+
}
264+
if !cmp.Equal(expectedProblems, problems) {
265+
t.Error(cmp.Diff(expectedProblems, problems))
266+
}
267+
}
268+
188269
// WIP - Jakub
189270
// TODO: vsr route selector test
190271
func TestAddVirtualServerWithVirtualServerRoutesVSR(t *testing.T) {

0 commit comments

Comments
 (0)