Add tenancy tests for routes controller (#19706)

This commit is contained in:
Ganesh S 2023-11-22 21:52:10 +05:30 committed by GitHub
parent 0fdc2ac5e9
commit ba2422596f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2692 additions and 2653 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -52,11 +52,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
t.Run("with no service", func(t *testing.T) { t.Run("with no service", func(t *testing.T) {
sg := newTestServiceGetter() sg := newTestServiceGetter()
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{ got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), ""), newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), ""),
}, nil) }, nil)
require.Len(t, got, 1) require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionMissingParentRef( prototest.AssertContainsElement(t, got, ConditionMissingParentRef(
newRef(pbcatalog.ServiceType, "api"), newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
)) ))
}) })
@ -65,11 +65,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"http": pbcatalog.Protocol_PROTOCOL_HTTP, "http": pbcatalog.Protocol_PROTOCOL_HTTP,
})) }))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{ got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), ""), newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), ""),
}, nil) }, nil)
require.Len(t, got, 1) require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionParentRefOutsideMesh( prototest.AssertContainsElement(t, got, ConditionParentRefOutsideMesh(
newRef(pbcatalog.ServiceType, "api"), newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
)) ))
}) })
@ -79,11 +79,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH, "mesh": pbcatalog.Protocol_PROTOCOL_MESH,
})) }))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{ got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "mesh"), newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "mesh"),
}, nil) }, nil)
require.Len(t, got, 1) require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionParentRefUsingMeshPort( prototest.AssertContainsElement(t, got, ConditionParentRefUsingMeshPort(
newRef(pbcatalog.ServiceType, "api"), newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
"mesh", "mesh",
)) ))
}) })
@ -94,11 +94,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH, "mesh": pbcatalog.Protocol_PROTOCOL_MESH,
})) }))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{ got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "web"), newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "web"),
}, nil) }, nil)
require.Len(t, got, 1) require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionUnknownParentRefPort( prototest.AssertContainsElement(t, got, ConditionUnknownParentRefPort(
newRef(pbcatalog.ServiceType, "api"), newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
"web", "web",
)) ))
}) })
@ -109,7 +109,7 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH, "mesh": pbcatalog.Protocol_PROTOCOL_MESH,
})) }))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{ got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), ""), newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), ""),
}, nil) }, nil)
require.Empty(t, got) require.Empty(t, got)
}) })
@ -120,7 +120,7 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH, "mesh": pbcatalog.Protocol_PROTOCOL_MESH,
})) }))
got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{ got := computeNewRouteRefConditions(sg, []*pbmesh.ParentReference{
newParentRef(newRef(pbcatalog.ServiceType, "api"), "http"), newParentRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "http"),
}, nil) }, nil)
require.Empty(t, got) require.Empty(t, got)
}) })
@ -130,11 +130,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
t.Run("with no service", func(t *testing.T) { t.Run("with no service", func(t *testing.T) {
sg := newTestServiceGetter() sg := newTestServiceGetter()
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{ got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "", ""), newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "", ""),
}) })
require.Len(t, got, 1) require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionMissingBackendRef( prototest.AssertContainsElement(t, got, ConditionMissingBackendRef(
newRef(pbcatalog.ServiceType, "api"), newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
)) ))
}) })
@ -143,11 +143,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"http": pbcatalog.Protocol_PROTOCOL_HTTP, "http": pbcatalog.Protocol_PROTOCOL_HTTP,
})) }))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{ got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "", ""), newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "", ""),
}) })
require.Len(t, got, 1) require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionBackendRefOutsideMesh( prototest.AssertContainsElement(t, got, ConditionBackendRefOutsideMesh(
newRef(pbcatalog.ServiceType, "api"), newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
)) ))
}) })
@ -157,11 +157,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH, "mesh": pbcatalog.Protocol_PROTOCOL_MESH,
})) }))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{ got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "mesh", ""), newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "mesh", ""),
}) })
require.Len(t, got, 1) require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionBackendRefUsingMeshPort( prototest.AssertContainsElement(t, got, ConditionBackendRefUsingMeshPort(
newRef(pbcatalog.ServiceType, "api"), newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
"mesh", "mesh",
)) ))
}) })
@ -172,11 +172,11 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH, "mesh": pbcatalog.Protocol_PROTOCOL_MESH,
})) }))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{ got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "web", ""), newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "web", ""),
}) })
require.Len(t, got, 1) require.Len(t, got, 1)
prototest.AssertContainsElement(t, got, ConditionUnknownBackendRefPort( prototest.AssertContainsElement(t, got, ConditionUnknownBackendRefPort(
newRef(pbcatalog.ServiceType, "api"), newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()),
"web", "web",
)) ))
}) })
@ -187,7 +187,7 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH, "mesh": pbcatalog.Protocol_PROTOCOL_MESH,
})) }))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{ got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "", ""), newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "", ""),
}) })
require.Empty(t, got) require.Empty(t, got)
}) })
@ -198,16 +198,20 @@ func TestComputeNewRouteRefConditions(t *testing.T) {
"mesh": pbcatalog.Protocol_PROTOCOL_MESH, "mesh": pbcatalog.Protocol_PROTOCOL_MESH,
})) }))
got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{ got := computeNewRouteRefConditions(sg, nil, []*pbmesh.BackendReference{
newBackendRef(newRef(pbcatalog.ServiceType, "api"), "http", ""), newBackendRef(newRef(pbcatalog.ServiceType, "api", resource.DefaultNamespacedTenancy()), "http", ""),
}) })
require.Empty(t, got) require.Empty(t, got)
}) })
}) })
} }
func newRef(typ *pbresource.Type, name string) *pbresource.Reference { func newRef(typ *pbresource.Type, name string, tenancy *pbresource.Tenancy) *pbresource.Reference {
if tenancy == nil {
tenancy = resource.DefaultNamespacedTenancy()
}
return rtest.Resource(typ, name). return rtest.Resource(typ, name).
WithTenancy(resource.DefaultNamespacedTenancy()). WithTenancy(tenancy).
Reference("") Reference("")
} }