Skip to content

Commit 9bea014

Browse files
committed
feat: update unit-tests
1 parent a1af157 commit 9bea014

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/plugin/plugin_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestRunSuccessfully(t *testing.T) {
3636
HTTPRouteClient: gwFake.NewSimpleClientset(&mocks.HTTPRouteObj).GatewayV1().HTTPRoutes(mocks.RolloutNamespace),
3737
GRPCRouteClient: gwFake.NewSimpleClientset(&mocks.GRPCRouteObj).GatewayV1().GRPCRoutes(mocks.RolloutNamespace),
3838
TCPRouteClient: gwFake.NewSimpleClientset(&mocks.TCPPRouteObj).GatewayV1alpha2().TCPRoutes(mocks.RolloutNamespace),
39+
TLSRouteClient: gwFake.NewSimpleClientset(&mocks.TLSRouteObj).GatewayV1alpha2().TLSRoutes(mocks.RolloutNamespace),
3940
TestClientset: fake.NewSimpleClientset(&mocks.ConfigMapObj).CoreV1().ConfigMaps(mocks.RolloutNamespace),
4041
}
4142

@@ -138,6 +139,19 @@ func TestRunSuccessfully(t *testing.T) {
138139
assert.Equal(t, 100-desiredWeight, *(rpcPluginImp.UpdatedTCPRouteMock.Spec.Rules[0].BackendRefs[0].Weight))
139140
assert.Equal(t, desiredWeight, *(rpcPluginImp.UpdatedTCPRouteMock.Spec.Rules[0].BackendRefs[1].Weight))
140141
})
142+
t.Run("SetTLSRouteWeight", func(t *testing.T) {
143+
var desiredWeight int32 = 30
144+
rollout := newRollout(mocks.StableServiceName, mocks.CanaryServiceName,
145+
&GatewayAPITrafficRouting{
146+
Namespace: mocks.RolloutNamespace,
147+
TLSRoute: mocks.TLSRouteName,
148+
})
149+
err := pluginInstance.SetWeight(rollout, desiredWeight, []v1alpha1.WeightDestination{})
150+
151+
assert.Empty(t, err.Error())
152+
assert.Equal(t, 100-desiredWeight, *(rpcPluginImp.UpdatedTLSRouteMock.Spec.Rules[0].BackendRefs[0].Weight))
153+
assert.Equal(t, desiredWeight, *(rpcPluginImp.UpdatedTLSRouteMock.Spec.Rules[0].BackendRefs[1].Weight))
154+
})
141155
t.Run("SetWeightViaRoutes", func(t *testing.T) {
142156
var desiredWeight int32 = 30
143157
rollout := newRollout(mocks.StableServiceName, mocks.CanaryServiceName,
@@ -155,6 +169,11 @@ func TestRunSuccessfully(t *testing.T) {
155169
UseHeaderRoutes: true,
156170
},
157171
},
172+
TLSRoutes: []TLSRoute{
173+
{
174+
Name: mocks.TLSRouteName,
175+
},
176+
},
158177
})
159178
err := pluginInstance.SetWeight(rollout, desiredWeight, []v1alpha1.WeightDestination{})
160179

@@ -163,6 +182,8 @@ func TestRunSuccessfully(t *testing.T) {
163182
assert.Equal(t, desiredWeight, *(rpcPluginImp.UpdatedHTTPRouteMock.Spec.Rules[0].BackendRefs[1].Weight))
164183
assert.Equal(t, 100-desiredWeight, *(rpcPluginImp.UpdatedTCPRouteMock.Spec.Rules[0].BackendRefs[0].Weight))
165184
assert.Equal(t, desiredWeight, *(rpcPluginImp.UpdatedTCPRouteMock.Spec.Rules[0].BackendRefs[1].Weight))
185+
assert.Equal(t, 100-desiredWeight, *(rpcPluginImp.UpdatedTLSRouteMock.Spec.Rules[0].BackendRefs[0].Weight))
186+
assert.Equal(t, desiredWeight, *(rpcPluginImp.UpdatedTLSRouteMock.Spec.Rules[0].BackendRefs[1].Weight))
166187
})
167188
t.Run("SetHTTPHeaderRoute", func(t *testing.T) {
168189
headerName := "X-Test"

0 commit comments

Comments
 (0)