Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

test(*): Update test fixtures to have multiple traffic targets #2525

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/catalog/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func newFakeMeshCatalogForRoutes(t *testing.T, testParams testParams) *MeshCatal

mockConfigurator.EXPECT().IsPermissiveTrafficPolicyMode().Return(testParams.permissiveMode).AnyTimes()

mockMeshSpec.EXPECT().ListTrafficTargets().Return([]*access.TrafficTarget{&tests.TrafficTarget}).AnyTimes()
mockMeshSpec.EXPECT().ListTrafficTargets().Return([]*access.TrafficTarget{&tests.TrafficTarget, &tests.BookstoreV2TrafficTarget}).AnyTimes()
mockMeshSpec.EXPECT().ListHTTPTrafficSpecs().Return([]*specs.HTTPRouteGroup{&tests.HTTPRouteGroup}).AnyTimes()

return NewMeshCatalog(mockKubeController, kubeClient, mockMeshSpec, certManager,
Expand Down
21 changes: 0 additions & 21 deletions pkg/catalog/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ func TestListTrafficTargetPermutations(t *testing.T) {

expected := []string{
utils.GetTrafficTargetName(tests.TrafficTargetName, tests.BookbuyerService, tests.BookstoreV1Service),
utils.GetTrafficTargetName(tests.TrafficTargetName, tests.BookbuyerService, tests.BookstoreV2Service),
utils.GetTrafficTargetName(tests.TrafficTargetName, tests.BookbuyerService, tests.BookstoreApexService),
}
assert.ElementsMatch(actualTargetNames, expected)
Expand Down Expand Up @@ -1556,26 +1555,6 @@ func TestListPoliciesFromTrafficTargets(t *testing.T) {
},
},
},
{
Name: "bookstore-v2.default",
Hostnames: tests.BookstoreV2Hostnames,
Rules: []*trafficpolicy.Rule{
{
Route: trafficpolicy.RouteWeightedClusters{
HTTPRouteMatch: tests.BookstoreBuyHTTPRoute,
WeightedClusters: mapset.NewSet(tests.BookstoreV2DefaultWeightedCluster),
},
AllowedServiceAccounts: mapset.NewSet(tests.BookbuyerServiceAccount),
},
{
Route: trafficpolicy.RouteWeightedClusters{
HTTPRouteMatch: tests.BookstoreSellHTTPRoute,
WeightedClusters: mapset.NewSet(tests.BookstoreV2DefaultWeightedCluster),
},
AllowedServiceAccounts: mapset.NewSet(tests.BookbuyerServiceAccount),
},
},
},
{
Name: "bookstore-apex.default",
Hostnames: tests.BookstoreApexHostnames,
Expand Down
5 changes: 3 additions & 2 deletions pkg/endpoint/providers/kube/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ func NewFakeProvider() endpoint.Provider {
tests.BookstoreApexService.String(): {tests.Endpoint},
},
services: map[service.K8sServiceAccount][]service.MeshService{
tests.BookstoreServiceAccount: {tests.BookstoreV1Service, tests.BookstoreV2Service, tests.BookstoreApexService},
tests.BookbuyerServiceAccount: {tests.BookbuyerService},
tests.BookstoreServiceAccount: {tests.BookstoreV1Service, tests.BookstoreApexService},
tests.BookstoreV2ServiceAccount: {tests.BookstoreV2Service},
tests.BookbuyerServiceAccount: {tests.BookbuyerService},
},
}
}
Expand Down
17 changes: 16 additions & 1 deletion pkg/envoy/eds/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"fmt"
"testing"

xds_endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
"github.com/golang/mock/gomock"
"github.com/golang/protobuf/ptypes"
tassert "github.com/stretchr/testify/assert"
"k8s.io/client-go/kubernetes"
testclient "k8s.io/client-go/kubernetes/fake"
Expand Down Expand Up @@ -61,6 +63,19 @@ func TestEndpointConfiguration(t *testing.T) {
assert.NotNil(proxy)

actual, err := NewResponse(meshCatalog, proxy, nil, mockConfigurator, nil)
assert.Empty(err)
assert.Nil(err)
assert.NotNil(actual)

// There are 3 endpoints configured based on the configuration:
// 1. Bookstore
// 2. Bookstore-v1
// 3. Bookstore-v2
assert.Len(actual.Resources, 3)

loadAssignment := xds_endpoint.ClusterLoadAssignment{}

// validating an endpoint
err = ptypes.UnmarshalAny(actual.Resources[0], &loadAssignment)
assert.Nil(err)
assert.Len(loadAssignment.Endpoints, 1)
}
2 changes: 1 addition & 1 deletion pkg/smi/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewFakeMeshSpecClient() MeshSpec {
trafficSplits: []*split.TrafficSplit{&tests.TrafficSplit},
httpRouteGroups: []*spec.HTTPRouteGroup{&tests.HTTPRouteGroup},
tcpRoutes: []*spec.TCPRoute{&tests.TCPRoute},
trafficTargets: []*access.TrafficTarget{&tests.TrafficTarget},
trafficTargets: []*access.TrafficTarget{&tests.TrafficTarget, &tests.BookstoreV2TrafficTarget},
weightedServices: []service.WeightedService{tests.BookstoreV1WeightedService, tests.BookstoreV2WeightedService},
serviceAccounts: []service.K8sServiceAccount{
tests.BookstoreServiceAccount,
Expand Down
37 changes: 37 additions & 0 deletions pkg/tests/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const (
BookstoreServiceAccountName = "bookstore"
// BookbuyerServiceAccountName is the name of the bookbuyer service account
BookbuyerServiceAccountName = "bookbuyer"
// BookstoreV2ServiceAccountName is the name of the bookstore-v2 service account
BookstoreV2ServiceAccountName = "bookstore-v2"

// TrafficTargetName is the name of the traffic target SMI object.
TrafficTargetName = "bookbuyer-access-bookstore"
Expand Down Expand Up @@ -325,6 +327,35 @@ var (
},
}

// BookstoreV2TrafficTarget is a traffic target SMI object for bookstore-v2.
BookstoreV2TrafficTarget = access.TrafficTarget{
TypeMeta: v1.TypeMeta{
APIVersion: "access.smi-spec.io/v1alpha3",
Kind: "TrafficTarget",
},
ObjectMeta: v1.ObjectMeta{
Name: TrafficTargetName,
Namespace: "default",
},
Spec: access.TrafficTargetSpec{
Destination: access.IdentityBindingSubject{
Kind: "Name",
Name: BookstoreV2ServiceAccountName,
Namespace: "default",
},
Sources: []access.IdentityBindingSubject{{
Kind: "Name",
Name: BookbuyerServiceAccountName,
Namespace: "default",
}},
Rules: []access.TrafficTargetRule{{
Kind: "HTTPRouteGroup",
Name: RouteGroupName,
Matches: []string{BuyBooksMatchName, SellBooksMatchName},
}},
},
}

// RoutePolicyMap is a map of a key to a route policy SMI object.
RoutePolicyMap = map[trafficpolicy.TrafficSpecName]map[trafficpolicy.TrafficSpecMatchName]trafficpolicy.HTTPRouteMatch{
trafficpolicy.TrafficSpecName(fmt.Sprintf("HTTPRouteGroup/%s/%s", Namespace, RouteGroupName)): {
Expand All @@ -339,6 +370,12 @@ var (
Name: BookstoreServiceAccountName,
}

// BookstoreV2ServiceAccount is a namespaced service account.
BookstoreV2ServiceAccount = service.K8sServiceAccount{
Namespace: Namespace,
Name: BookstoreV2ServiceAccountName,
}

// BookbuyerServiceAccount is a namespaced bookbuyer account.
BookbuyerServiceAccount = service.K8sServiceAccount{
Namespace: Namespace,
Expand Down