Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Use order-insensitive assertion, remove redundant check
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancoleman committed Jul 1, 2022
1 parent 931c564 commit 34bf843
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/k8s/controllers/http_route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *HTTPRouteReconciler) getRoutesAffectedByService(service *corev1.Service
for _, ref := range rule.BackendRefs {
// The BackendRef may or may not specify a namespace, defaults to route's namespace
refNamespace := route.Namespace
if ref.Namespace != nil && *ref.Namespace != "" {
if ref.Namespace != nil {
refNamespace = string(*ref.Namespace)
}

Expand Down
15 changes: 8 additions & 7 deletions internal/k8s/controllers/http_route_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func TestHTTPRoute(t *testing.T) {
})
if test.err != nil {
require.Error(t, err)
require.ErrorIs(t, err, test.err)
assert.ErrorIs(t, err, test.err)
} else {
require.NoError(t, err)
}
require.Equal(t, test.result, result)
assert.Equal(t, test.result, result)
})
}
}
Expand Down Expand Up @@ -159,9 +159,10 @@ func TestHTTPRouteServiceToRouteRequests(t *testing.T) {
}

requests := controller.serviceToRouteRequests(svc)
require.Len(t, requests, 2)
assert.Equal(t, "namespace-1/route-1", requests[0].String())
assert.Equal(t, "namespace-2/route-2", requests[1].String())
assert.ElementsMatch(t, []reconcile.Request{
{NamespacedName: types.NamespacedName{Namespace: "namespace-1", Name: "route-1"}},
{NamespacedName: types.NamespacedName{Namespace: "namespace-2", Name: "route-2"}},
}, requests)
}

func TestHTTPRouteReferenceGrantToRouteRequests(t *testing.T) {
Expand Down Expand Up @@ -245,7 +246,7 @@ func TestHTTPRouteReferenceGrantToRouteRequests(t *testing.T) {

requests := controller.referenceGrantToRouteRequests(&refGrant)

require.Equal(t, []reconcile.Request{{
assert.Equal(t, []reconcile.Request{{
NamespacedName: types.NamespacedName{
Name: "httproute",
Namespace: "namespace1",
Expand Down Expand Up @@ -334,7 +335,7 @@ func TestHTTPRouteReferencePolicyToRouteRequests(t *testing.T) {

requests := controller.referencePolicyToRouteRequests(&refPolicy)

require.Equal(t, []reconcile.Request{{
assert.Equal(t, []reconcile.Request{{
NamespacedName: types.NamespacedName{
Name: "httproute",
Namespace: "namespace1",
Expand Down
2 changes: 1 addition & 1 deletion internal/k8s/controllers/tcp_route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *TCPRouteReconciler) getRoutesAffectedByService(service *corev1.Service)
for _, ref := range rule.BackendRefs {
// The BackendRef may or may not specify a namespace, defaults to route's namespace
refNamespace := route.Namespace
if ref.Namespace != nil && *ref.Namespace != "" {
if ref.Namespace != nil {
refNamespace = string(*ref.Namespace)
}

Expand Down
7 changes: 4 additions & 3 deletions internal/k8s/controllers/tcp_route_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ func TestTCPRouteServiceToRouteRequests(t *testing.T) {
}

requests := controller.serviceToRouteRequests(svc)
require.Len(t, requests, 2)
assert.Equal(t, "namespace-1/route-1", requests[0].String())
assert.Equal(t, "namespace-2/route-2", requests[1].String())
assert.ElementsMatch(t, []reconcile.Request{
{NamespacedName: types.NamespacedName{Namespace: "namespace-1", Name: "route-1"}},
{NamespacedName: types.NamespacedName{Namespace: "namespace-2", Name: "route-2"}},
}, requests)
}

0 comments on commit 34bf843

Please sign in to comment.