Skip to content

Commit 65e8a2a

Browse files
committed
update test converage
1 parent db6e642 commit 65e8a2a

File tree

1 file changed

+126
-84
lines changed

1 file changed

+126
-84
lines changed

internal/mode/static/state/dataplane/configuration_test.go

Lines changed: 126 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,52 +3344,60 @@ func TestBuildAdditions(t *testing.T) {
33443344
func TestCreatePassthroughServers(t *testing.T) {
33453345
testGraph := graph.Graph{
33463346
Gateway: &graph.Gateway{
3347-
Listeners: make([]*graph.Listener, 0, 1),
3348-
},
3349-
}
3350-
l4routes := make(map[graph.L4RouteKey]*graph.L4Route)
3351-
3352-
nsname := types.NamespacedName{
3353-
Namespace: "default",
3354-
Name: "secure-app",
3355-
}
3356-
3357-
key := graph.L4RouteKey{NamespacedName: nsname}
3358-
l4routes[key] = &graph.L4Route{
3359-
Spec: graph.L4RouteSpec{
3360-
Hostnames: []v1.Hostname{"app.example.com", "cafe.example.com"},
3361-
BackendRef: graph.BackendRef{
3362-
SvcNsName: nsname,
3363-
ServicePort: apiv1.ServicePort{
3364-
Name: "https",
3365-
Protocol: "TCP",
3366-
AppProtocol: nil,
3367-
Port: 8443,
3368-
TargetPort: intstr.IntOrString{
3369-
Type: intstr.Int,
3370-
IntVal: 8443,
3347+
Listeners: []*graph.Listener{
3348+
{
3349+
Name: "testingListener",
3350+
Source: v1.Listener{
3351+
Protocol: v1.TLSProtocolType,
3352+
Port: 443,
3353+
},
3354+
Routes: make(map[graph.RouteKey]*graph.L7Route),
3355+
L4Routes: map[graph.L4RouteKey]*graph.L4Route{
3356+
{NamespacedName: types.NamespacedName{
3357+
Namespace: "default",
3358+
Name: "secure-app",
3359+
}}: {
3360+
Spec: graph.L4RouteSpec{
3361+
Hostnames: []v1.Hostname{"app.example.com", "cafe.example.com"},
3362+
BackendRef: graph.BackendRef{
3363+
SvcNsName: types.NamespacedName{
3364+
Namespace: "default",
3365+
Name: "secure-app",
3366+
},
3367+
ServicePort: apiv1.ServicePort{
3368+
Name: "https",
3369+
Protocol: "TCP",
3370+
Port: 8443,
3371+
TargetPort: intstr.IntOrString{
3372+
Type: intstr.Int,
3373+
IntVal: 8443,
3374+
},
3375+
},
3376+
Valid: true,
3377+
},
3378+
},
3379+
Valid: true,
3380+
},
3381+
{NamespacedName: types.NamespacedName{
3382+
Namespace: "default",
3383+
Name: "secure-app2",
3384+
}}: {},
3385+
{NamespacedName: types.NamespacedName{
3386+
Namespace: "default",
3387+
Name: "secure-app3",
3388+
}}: {
3389+
Valid: true,
3390+
Spec: graph.L4RouteSpec{
3391+
Hostnames: []v1.Hostname{"test.example.com"},
3392+
BackendRef: graph.BackendRef{},
3393+
},
3394+
},
33713395
},
3396+
Valid: true,
33723397
},
3373-
Valid: true,
33743398
},
33753399
},
3376-
Valid: true,
33773400
}
3378-
testGraph.Gateway.Listeners = append(testGraph.Gateway.Listeners, &graph.Listener{
3379-
Name: "testingListener",
3380-
Source: v1.Listener{
3381-
Protocol: v1.TLSProtocolType,
3382-
Port: 443,
3383-
},
3384-
Routes: make(map[graph.RouteKey]*graph.L7Route),
3385-
L4Routes: l4routes,
3386-
AllowedRouteLabelSelector: nil,
3387-
ResolvedSecret: nil,
3388-
Conditions: nil,
3389-
SupportedKinds: nil,
3390-
Valid: true,
3391-
Attachable: false,
3392-
})
33933401

33943402
passthroughServers := buildPassthroughServers(&testGraph)
33953403

@@ -3414,61 +3422,95 @@ func TestCreatePassthroughServers(t *testing.T) {
34143422
func TestBuildStreamUpstreams(t *testing.T) {
34153423
testGraph := graph.Graph{
34163424
Gateway: &graph.Gateway{
3417-
Listeners: make([]*graph.Listener, 0, 1),
3418-
},
3419-
}
3420-
l4routes := make(map[graph.L4RouteKey]*graph.L4Route)
3421-
3422-
nsname := types.NamespacedName{
3423-
Namespace: "default",
3424-
Name: "secure-app",
3425-
}
3426-
3427-
key := graph.L4RouteKey{NamespacedName: nsname}
3428-
l4routes[key] = &graph.L4Route{
3429-
Spec: graph.L4RouteSpec{
3430-
Hostnames: []v1.Hostname{"app.example.com", "cafe.example.com"},
3431-
BackendRef: graph.BackendRef{
3432-
SvcNsName: nsname,
3433-
ServicePort: apiv1.ServicePort{
3434-
Name: "https",
3435-
Protocol: "TCP",
3436-
AppProtocol: nil,
3437-
Port: 8443,
3438-
TargetPort: intstr.IntOrString{
3439-
Type: intstr.Int,
3440-
IntVal: 8443,
3425+
Listeners: []*graph.Listener{
3426+
{
3427+
Name: "testingListener",
3428+
Source: v1.Listener{
3429+
Protocol: v1.TLSProtocolType,
3430+
Port: 443,
34413431
},
3432+
Routes: make(map[graph.RouteKey]*graph.L7Route),
3433+
L4Routes: map[graph.L4RouteKey]*graph.L4Route{
3434+
{NamespacedName: types.NamespacedName{
3435+
Namespace: "default",
3436+
Name: "secure-app",
3437+
}}: {
3438+
Spec: graph.L4RouteSpec{
3439+
Hostnames: []v1.Hostname{"app.example.com", "cafe.example.com"},
3440+
BackendRef: graph.BackendRef{
3441+
SvcNsName: types.NamespacedName{
3442+
Namespace: "default",
3443+
Name: "secure-app",
3444+
},
3445+
ServicePort: apiv1.ServicePort{
3446+
Name: "https",
3447+
Protocol: "TCP",
3448+
Port: 8443,
3449+
TargetPort: intstr.IntOrString{
3450+
Type: intstr.Int,
3451+
IntVal: 8443,
3452+
},
3453+
},
3454+
Valid: true,
3455+
},
3456+
},
3457+
Valid: true,
3458+
},
3459+
{NamespacedName: types.NamespacedName{
3460+
Namespace: "default",
3461+
Name: "secure-app2",
3462+
}}: {},
3463+
{NamespacedName: types.NamespacedName{
3464+
Namespace: "default",
3465+
Name: "secure-app3",
3466+
}}: {
3467+
Valid: true,
3468+
Spec: graph.L4RouteSpec{
3469+
Hostnames: []v1.Hostname{"test.example.com"},
3470+
BackendRef: graph.BackendRef{},
3471+
},
3472+
},
3473+
{NamespacedName: types.NamespacedName{
3474+
Namespace: "default",
3475+
Name: "secure-app4",
3476+
}}: {
3477+
Spec: graph.L4RouteSpec{
3478+
Hostnames: []v1.Hostname{"app.example.com", "cafe.example.com"},
3479+
BackendRef: graph.BackendRef{
3480+
SvcNsName: types.NamespacedName{
3481+
Namespace: "default",
3482+
Name: "secure-app",
3483+
},
3484+
ServicePort: apiv1.ServicePort{
3485+
Name: "https",
3486+
Protocol: "TCP",
3487+
Port: 8443,
3488+
TargetPort: intstr.IntOrString{
3489+
Type: intstr.Int,
3490+
IntVal: 8443,
3491+
},
3492+
},
3493+
Valid: true,
3494+
},
3495+
},
3496+
Valid: true,
3497+
},
3498+
},
3499+
Valid: true,
34423500
},
3443-
Valid: true,
34443501
},
34453502
},
3446-
Valid: true,
34473503
}
34483504

34493505
fakeResolver := resolverfakes.FakeServiceResolver{}
3450-
fakeResolver.ResolveReturns(nil, nil)
3451-
testGraph.Gateway.Listeners = append(testGraph.Gateway.Listeners, &graph.Listener{
3452-
Name: "testingListener",
3453-
Source: v1.Listener{
3454-
Protocol: v1.TLSProtocolType,
3455-
Port: 443,
3456-
},
3457-
Routes: make(map[graph.RouteKey]*graph.L7Route),
3458-
L4Routes: l4routes,
3459-
AllowedRouteLabelSelector: nil,
3460-
ResolvedSecret: nil,
3461-
Conditions: nil,
3462-
SupportedKinds: nil,
3463-
Valid: true,
3464-
Attachable: false,
3465-
})
3506+
fakeResolver.ResolveReturns(nil, errors.New("error"))
34663507

34673508
streamUpstreams := buildStreamUpstreams(context.Background(), testGraph.Gateway.Listeners, &fakeResolver)
34683509

34693510
expectedStreamUpstreams := []Upstream{
34703511
{
3471-
Name: "default_secure-app_8443",
3512+
Name: "default_secure-app_8443",
3513+
ErrorMsg: "error",
34723514
},
34733515
}
34743516
g := NewWithT(t)

0 commit comments

Comments
 (0)