Skip to content

Commit

Permalink
add test for AddListenerCondition
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <krisss@vmware.com>
  • Loading branch information
skriss committed Nov 30, 2021
1 parent b042e1c commit fe1863b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions internal/status/gatewaystatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,40 @@ func TestGatewayMutate(t *testing.T) {
}
assert.ElementsMatch(t, want, got.Status.Listeners)
}

func TestGatewayAddListenerCondition(t *testing.T) {
var gsu GatewayStatusUpdate

// first condition for listener-1
res := gsu.AddListenerCondition("listener-1", gatewayapi_v1alpha2.ListenerConditionReady, metav1.ConditionFalse, gatewayapi_v1alpha2.ListenerReasonInvalid, "message 1")
assert.Len(t, gsu.ListenerStatus["listener-1"].Conditions, 1)
assert.Equal(t, string(gatewayapi_v1alpha2.ListenerConditionReady), res.Type)
assert.Equal(t, metav1.ConditionFalse, res.Status)
assert.Equal(t, string(gatewayapi_v1alpha2.ListenerReasonInvalid), res.Reason)
assert.Equal(t, "message 1", res.Message)

// second condition (different type) for listener-1
res = gsu.AddListenerCondition("listener-1", gatewayapi_v1alpha2.ListenerConditionDetached, metav1.ConditionTrue, gatewayapi_v1alpha2.ListenerReasonUnsupportedProtocol, "message 2")
assert.Len(t, gsu.ListenerStatus["listener-1"].Conditions, 2)
assert.Equal(t, string(gatewayapi_v1alpha2.ListenerConditionDetached), res.Type)
assert.Equal(t, metav1.ConditionTrue, res.Status)
assert.Equal(t, string(gatewayapi_v1alpha2.ListenerReasonUnsupportedProtocol), res.Reason)
assert.Equal(t, "message 2", res.Message)

// first condition for listener-2
res = gsu.AddListenerCondition("listener-2", gatewayapi_v1alpha2.ListenerConditionReady, metav1.ConditionFalse, gatewayapi_v1alpha2.ListenerReasonInvalid, "message 3")
assert.Len(t, gsu.ListenerStatus["listener-2"].Conditions, 1)
assert.Len(t, gsu.ListenerStatus["listener-1"].Conditions, 2)
assert.Equal(t, string(gatewayapi_v1alpha2.ListenerConditionReady), res.Type)
assert.Equal(t, metav1.ConditionFalse, res.Status)
assert.Equal(t, string(gatewayapi_v1alpha2.ListenerReasonInvalid), res.Reason)
assert.Equal(t, "message 3", res.Message)

// third condition (pre-existing type) for listener-1
res = gsu.AddListenerCondition("listener-1", gatewayapi_v1alpha2.ListenerConditionDetached, metav1.ConditionTrue, gatewayapi_v1alpha2.ListenerReasonUnsupportedProtocol, "message 4")
assert.Len(t, gsu.ListenerStatus["listener-1"].Conditions, 2)
assert.Equal(t, string(gatewayapi_v1alpha2.ListenerConditionDetached), res.Type)
assert.Equal(t, metav1.ConditionTrue, res.Status)
assert.Equal(t, string(gatewayapi_v1alpha2.ListenerReasonUnsupportedProtocol), res.Reason)
assert.Equal(t, "message 2, message 4", res.Message)
}

0 comments on commit fe1863b

Please sign in to comment.