Skip to content

Commit

Permalink
test(trafficSplit): Add a test for service with zero weight in traffi…
Browse files Browse the repository at this point in the history
…c split

A unit test has been added in tests/scenarios to validate a service
having zero weight in traffic split

Fixes # 2424

Signed-off-by: Sneha Chhabria <snchh@microsoft.com>
  • Loading branch information
snehachhabria committed Feb 25, 2021
1 parent 66a1a5f commit 5271e26
Show file tree
Hide file tree
Showing 3 changed files with 386 additions and 23 deletions.
46 changes: 23 additions & 23 deletions pkg/catalog/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var expectedBookbuyerOutbound []*trafficpolicy.OutboundTrafficPolicy = []*traffi
Hostnames: tests.BookstoreV1Hostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookstoreV1DefaultWeightedCluster),
},
},
Expand All @@ -43,7 +43,7 @@ var expectedBookbuyerOutbound []*trafficpolicy.OutboundTrafficPolicy = []*traffi
Hostnames: tests.BookstoreV2Hostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookstoreV2DefaultWeightedCluster),
},
},
Expand All @@ -53,7 +53,7 @@ var expectedBookbuyerOutbound []*trafficpolicy.OutboundTrafficPolicy = []*traffi
Hostnames: tests.BookstoreApexHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookstoreApexDefaultWeightedCluster),
},
},
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestListOutboundTrafficPolicies(t *testing.T) {
Hostnames: tests.BookstoreV1Hostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookstoreV1DefaultWeightedCluster),
},
},
Expand All @@ -117,7 +117,7 @@ func TestListOutboundTrafficPolicies(t *testing.T) {
Hostnames: tests.BookstoreV2Hostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookstoreV2DefaultWeightedCluster),
},
},
Expand All @@ -127,7 +127,7 @@ func TestListOutboundTrafficPolicies(t *testing.T) {
Hostnames: tests.BookstoreApexHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSetFromSlice([]interface{}{
service.WeightedCluster{ClusterName: "default/bookstore-v1", Weight: 90},
service.WeightedCluster{ClusterName: "default/bookstore-v2", Weight: 10},
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestListOutboundTrafficPolicies(t *testing.T) {
Hostnames: tests.BookstoreApexHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSetFromSlice([]interface{}{
service.WeightedCluster{ClusterName: "default/bookstore-v1", Weight: 90},
service.WeightedCluster{ClusterName: "default/bookstore-v2", Weight: 10},
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestListOutboundTrafficPolicies(t *testing.T) {
},
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookstoreV1DefaultWeightedCluster),
},
},
Expand All @@ -224,7 +224,7 @@ func TestListOutboundTrafficPolicies(t *testing.T) {
},
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookstoreV2DefaultWeightedCluster),
},
},
Expand All @@ -243,7 +243,7 @@ func TestListOutboundTrafficPolicies(t *testing.T) {
},
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookbuyerDefaultWeightedCluster),
},
},
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestListOutboundTrafficPoliciesForTrafficSplits(t *testing.T) {
Hostnames: tests.BookstoreApexNamespacedHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSetFromSlice([]interface{}{
service.WeightedCluster{ClusterName: "default/bookstore-v1", Weight: 90},
service.WeightedCluster{ClusterName: "default/bookstore-v2", Weight: 10},
Expand All @@ -501,7 +501,7 @@ func TestListOutboundTrafficPoliciesForTrafficSplits(t *testing.T) {
Hostnames: tests.BookstoreApexHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSetFromSlice([]interface{}{
service.WeightedCluster{ClusterName: "default/bookstore-v1", Weight: 90},
service.WeightedCluster{ClusterName: "default/bookstore-v2", Weight: 10},
Expand Down Expand Up @@ -531,7 +531,7 @@ func TestListOutboundTrafficPoliciesForTrafficSplits(t *testing.T) {
Hostnames: tests.BookstoreApexNamespacedHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSetFromSlice([]interface{}{
service.WeightedCluster{ClusterName: "default/bookstore-v1", Weight: 90},
service.WeightedCluster{ClusterName: "default/bookstore-v2", Weight: 10},
Expand All @@ -544,7 +544,7 @@ func TestListOutboundTrafficPoliciesForTrafficSplits(t *testing.T) {
Hostnames: testSplit1NamespacedHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSetFromSlice([]interface{}{
service.WeightedCluster{ClusterName: "bar/bookstore-v1", Weight: 10},
service.WeightedCluster{ClusterName: "bar/bookstore-v2", Weight: 90},
Expand All @@ -570,7 +570,7 @@ func TestListOutboundTrafficPoliciesForTrafficSplits(t *testing.T) {
Hostnames: testSplit1NamespacedHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSetFromSlice([]interface{}{
service.WeightedCluster{ClusterName: "bar/bookstore-v1", Weight: 10},
service.WeightedCluster{ClusterName: "bar/bookstore-v2", Weight: 90},
Expand Down Expand Up @@ -600,7 +600,7 @@ func TestListOutboundTrafficPoliciesForTrafficSplits(t *testing.T) {
Hostnames: testSplit1NamespacedHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSetFromSlice([]interface{}{
service.WeightedCluster{ClusterName: "bar/bookstore-v1", Weight: 10},
service.WeightedCluster{ClusterName: "bar/bookstore-v2", Weight: 90},
Expand All @@ -613,7 +613,7 @@ func TestListOutboundTrafficPoliciesForTrafficSplits(t *testing.T) {
Hostnames: testSplit3NamespacedHostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSetFromSlice([]interface{}{
service.WeightedCluster{ClusterName: "baz/bookstore-v1", Weight: 10},
service.WeightedCluster{ClusterName: "baz/bookstore-v2", Weight: 90},
Expand Down Expand Up @@ -1278,7 +1278,7 @@ func TestBuildOutboundPolicies(t *testing.T) {
Hostnames: hostnames,
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(bookstoreWeightedCluster),
},
},
Expand Down Expand Up @@ -2014,7 +2014,7 @@ func TestListInboundTrafficPolicies(t *testing.T) {
Rules: []*trafficpolicy.Rule{
{
Route: trafficpolicy.RouteWeightedClusters{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookbuyerDefaultWeightedCluster),
},
AllowedServiceAccounts: mapset.NewSet(tests.BookbuyerServiceAccount, tests.BookstoreServiceAccount),
Expand Down Expand Up @@ -2249,7 +2249,7 @@ func TestBuildInboundPermissiveModePolicies(t *testing.T) {
Rules: []*trafficpolicy.Rule{
{
Route: trafficpolicy.RouteWeightedClusters{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(service.WeightedCluster{
ClusterName: "bookstore-ns/bookstore",
Weight: 100,
Expand Down Expand Up @@ -2331,7 +2331,7 @@ func TestBuildOutboundPermissiveModePolicies(t *testing.T) {
},
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookstoreApexDefaultWeightedCluster),
},
},
Expand All @@ -2350,7 +2350,7 @@ func TestBuildOutboundPermissiveModePolicies(t *testing.T) {
},
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookstoreV1DefaultWeightedCluster),
},
},
Expand All @@ -2369,7 +2369,7 @@ func TestBuildOutboundPermissiveModePolicies(t *testing.T) {
},
Routes: []*trafficpolicy.RouteWeightedClusters{
{
HTTPRouteMatch: wildCardRouteMatch,
HTTPRouteMatch: tests.WildCardRouteMatch,
WeightedClusters: mapset.NewSet(tests.BookbuyerDefaultWeightedCluster),
},
},
Expand Down
6 changes: 6 additions & 0 deletions pkg/tests/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ var (
SelectorKey: SelectorValue,
constants.EnvoyUniqueIDLabelName: ProxyUUID,
}

// WildCardRouteMatch is HTTPRouteMatch with wildcard path and method
WildCardRouteMatch trafficpolicy.HTTPRouteMatch = trafficpolicy.HTTPRouteMatch{
PathRegex: constants.RegexMatchAll,
Methods: []string{constants.WildcardHTTPMethod},
}
)

// NewPodFixture creates a new Pod struct for testing.
Expand Down
Loading

0 comments on commit 5271e26

Please sign in to comment.