Skip to content

Commit

Permalink
ref(test): Use distinct weights for weighted clusters (openservicemes…
Browse files Browse the repository at this point in the history
  • Loading branch information
ksubrmnn authored and draychev committed Oct 28, 2020
1 parent 982bb20 commit d4bbde8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/catalog/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var _ = Describe("Test catalog proxy register/unregister", func() {
Expect(trafficSplits[0].Spec.Service).To(Equal("bookstore-apex"))
Expect(weightedServices[0]).To(Equal(service.WeightedService{
Service: tests.BookstoreV1Service,
Weight: 100,
Weight: tests.Weight90,
RootService: "bookstore-apex"}))
Expect(serviceAccounts[0].String()).To(Equal("default/bookstore"))
Expect(routeGroups[0].Name).To(Equal("bookstore-service-routes"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/catalog/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func TestGetWeightedClusterForService(t *testing.T) {

expected := service.WeightedCluster{
ClusterName: "default/bookstore-v1",
Weight: 100,
Weight: tests.Weight90,
}
assert.Equal(weightedCluster, expected)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/debugger/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ func TestGetSMIPolicies(t *testing.T) {
responseRecorder := httptest.NewRecorder()
smiPoliciesHandler.ServeHTTP(responseRecorder, nil)
actualResponseBody := responseRecorder.Body.String()
expectedResponseBody := `{"traffic_splits":[{"metadata":{"name":"bar","namespace":"foo","creationTimestamp":null},"spec":{}}],"weighted_services":[{"service_name:omitempty":{"Namespace":"default","Name":"bookstore-v1"},"weight:omitempty":100,"root_service:omitempty":"bookstore-apex"},{"service_name:omitempty":{"Namespace":"default","Name":"bookstore-v2"},"weight:omitempty":100,"root_service:omitempty":"bookstore-apex"}],"service_accounts":[{"Namespace":"default","Name":"bookbuyer"}],"route_groups":[{"kind":"HTTPRouteGroup","apiVersion":"specs.smi-spec.io/v1alpha2","metadata":{"name":"bookstore-service-routes","namespace":"default","creationTimestamp":null},"spec":{"matches":[{"name":"buy-books","methods":["GET"],"pathRegex":"/buy","headers":[{"user-agent":"test-UA"}]},{"name":"sell-books","methods":["GET"],"pathRegex":"/sell","headers":[{"user-agent":"test-UA"}]},{"name":"allow-everything-on-header","headers":[{"user-agent":"test-UA"}]}]}}],"traffic_targets":[{"kind":"TrafficTarget","apiVersion":"access.smi-spec.io/v1alpha2","metadata":{"name":"bookbuyer-access-bookstore","namespace":"default","creationTimestamp":null},"spec":{"destination":{"kind":"Name","name":"bookstore","namespace":"default"},"sources":[{"kind":"Name","name":"bookbuyer","namespace":"default"}],"rules":[{"kind":"HTTPRouteGroup","name":"bookstore-service-routes","matches":["buy-books","sell-books"]}]}}]}`
expectedResponseBody := `{"traffic_splits":[{"metadata":{"name":"bar","namespace":"foo","creationTimestamp":null},"spec":{}}],"weighted_services":[{"service_name:omitempty":{"Namespace":"default","Name":"bookstore-v1"},"weight:omitempty":90,"root_service:omitempty":"bookstore-apex"},{"service_name:omitempty":{"Namespace":"default","Name":"bookstore-v2"},"weight:omitempty":10,"root_service:omitempty":"bookstore-apex"}],"service_accounts":[{"Namespace":"default","Name":"bookbuyer"}],"route_groups":[{"kind":"HTTPRouteGroup","apiVersion":"specs.smi-spec.io/v1alpha2","metadata":{"name":"bookstore-service-routes","namespace":"default","creationTimestamp":null},"spec":{"matches":[{"name":"buy-books","methods":["GET"],"pathRegex":"/buy","headers":[{"user-agent":"test-UA"}]},{"name":"sell-books","methods":["GET"],"pathRegex":"/sell","headers":[{"user-agent":"test-UA"}]},{"name":"allow-everything-on-header","headers":[{"user-agent":"test-UA"}]}]}}],"traffic_targets":[{"kind":"TrafficTarget","apiVersion":"access.smi-spec.io/v1alpha2","metadata":{"name":"bookbuyer-access-bookstore","namespace":"default","creationTimestamp":null},"spec":{"destination":{"kind":"Name","name":"bookstore","namespace":"default"},"sources":[{"kind":"Name","name":"bookbuyer","namespace":"default"}],"rules":[{"kind":"HTTPRouteGroup","name":"bookstore-service-routes","matches":["buy-books","sell-books"]}]}}]}`
assert.Equal(actualResponseBody, expectedResponseBody, "Actual value did not match expectations:\n%s", actualResponseBody)
}
2 changes: 1 addition & 1 deletion pkg/envoy/rds/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ var _ = Describe("RDS Response", func() {

expected := service.WeightedCluster{
ClusterName: service.ClusterName(tests.BookbuyerService.String()),
Weight: tests.Weight,
Weight: constants.ClusterWeightAcceptAll,
}
Expect(actual).To(Equal(expected))
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/smi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ var _ = Describe("When listing TrafficSplit", func() {
Backends: []smiSplit.TrafficSplitBackend{
{
Service: tests.BookstoreV1ServiceName,
Weight: tests.Weight,
Weight: tests.Weight90,
},
{
Service: tests.BookstoreV2ServiceName,
Weight: tests.Weight,
Weight: tests.Weight10,
},
},
},
Expand Down Expand Up @@ -155,11 +155,11 @@ var _ = Describe("When listing TrafficSplit services", func() {
Backends: []smiSplit.TrafficSplitBackend{
{
Service: "bookstore-v1",
Weight: tests.Weight,
Weight: tests.Weight90,
},
{
Service: "bookstore-v2",
Weight: tests.Weight,
Weight: tests.Weight10,
},
},
},
Expand Down
15 changes: 9 additions & 6 deletions pkg/tests/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ const (
// WildcardWithHeadersMatchName is the name of the match object.
WildcardWithHeadersMatchName = "allow-everything-on-header"

// Weight is the percentage of the traffic to be sent this way in a traffic split scenario.
Weight = 100
// Weight90 is the value representing a share of the traffic to be sent this way in a traffic split scenario.
Weight90 = 90

// Weight10 is the value representing a share of the traffic to be sent this way in a traffic split scenario.
Weight10 = 10

// RouteGroupName is the name of the route group SMI object.
RouteGroupName = "bookstore-service-routes"
Expand Down Expand Up @@ -222,11 +225,11 @@ var (
Backends: []v1alpha2.TrafficSplitBackend{
{
Service: BookstoreV1ServiceName,
Weight: Weight,
Weight: Weight90,
},
{
Service: BookstoreV2ServiceName,
Weight: Weight,
Weight: Weight10,
},
},
},
Expand Down Expand Up @@ -287,7 +290,7 @@ var (
Namespace: Namespace,
Name: BookstoreV1ServiceName,
},
Weight: Weight,
Weight: Weight90,
RootService: BookstoreApexServiceName,
}

Expand All @@ -297,7 +300,7 @@ var (
Namespace: Namespace,
Name: BookstoreV2ServiceName,
},
Weight: Weight,
Weight: Weight10,
RootService: BookstoreApexServiceName,
}

Expand Down

0 comments on commit d4bbde8

Please sign in to comment.