Skip to content

Commit

Permalink
test(policy): introduce new resources builders for tests (kumahq#8407)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcin Skalski <[email protected]>
  • Loading branch information
Automaat authored Nov 18, 2023
1 parent 1ab9dc1 commit 13d6b34
Show file tree
Hide file tree
Showing 15 changed files with 899 additions and 1,021 deletions.
22 changes: 4 additions & 18 deletions pkg/plugins/policies/meshaccesslog/plugin/v1alpha1/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
core_plugins "github.com/kumahq/kuma/pkg/core/plugins"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
core_model "github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/xds"
core_xds "github.com/kumahq/kuma/pkg/core/xds"
core_rules "github.com/kumahq/kuma/pkg/plugins/policies/core/rules"
Expand Down Expand Up @@ -73,15 +72,9 @@ var _ = Describe("MeshAccessLog", func() {
).
AddOutbounds(given.outbounds),
).
WithPolicies(xds.MatchedPolicies{
Dynamic: map[core_model.ResourceType]xds.TypedMatchingPolicies{
api.MeshAccessLogType: {
Type: api.MeshAccessLogType,
ToRules: given.toRules,
FromRules: given.fromRules,
},
},
}).
WithPolicies(
xds_builders.MatchedPolicies().WithPolicy(api.MeshAccessLogType, given.toRules, given.fromRules),
).
Build()
plugin := plugin.NewPlugin().(core_plugins.PolicyPlugin)

Expand Down Expand Up @@ -969,14 +962,7 @@ var _ = Describe("MeshAccessLog", func() {
WithMesh("default").
WithBuiltInGateway("gateway"),
).
WithPolicies(xds.MatchedPolicies{
Dynamic: map[core_model.ResourceType]xds.TypedMatchingPolicies{
api.MeshAccessLogType: {
Type: api.MeshAccessLogType,
ToRules: given.toRules,
},
},
}).
WithPolicies(xds_builders.MatchedPolicies().WithToPolicy(api.MeshAccessLogType, given.toRules)).
Build()

for n, p := range core_plugins.Plugins().ProxyPlugins() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
core_plugins "github.com/kumahq/kuma/pkg/core/plugins"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
core_model "github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/xds"
core_xds "github.com/kumahq/kuma/pkg/core/xds"
core_rules "github.com/kumahq/kuma/pkg/plugins/policies/core/rules"
api "github.com/kumahq/kuma/pkg/plugins/policies/meshcircuitbreaker/api/v1alpha1"
Expand Down Expand Up @@ -100,15 +98,9 @@ var _ = Describe("MeshCircuitBreaker", func() {
AddOutboundsToServices("other-service", "second-service").
WithInboundOfTags(mesh_proto.ServiceTag, "backend", mesh_proto.ProtocolTag, "http"),
).
WithPolicies(core_xds.MatchedPolicies{
Dynamic: map[core_model.ResourceType]core_xds.TypedMatchingPolicies{
api.MeshCircuitBreakerType: {
Type: api.MeshCircuitBreakerType,
FromRules: given.fromRules,
ToRules: given.toRules,
},
},
}).
WithPolicies(
xds_builders.MatchedPolicies().WithPolicy(api.MeshCircuitBreakerType, given.toRules, given.fromRules),
).
Build()
plugin := plugin.NewPlugin().(core_plugins.PolicyPlugin)

Expand Down Expand Up @@ -415,14 +407,7 @@ var _ = Describe("MeshCircuitBreaker", func() {
xdsCtx := xds_samples.SampleContextWith(resources)
proxy := xds_builders.Proxy().
WithDataplane(samples.GatewayDataplaneBuilder()).
WithPolicies(xds.MatchedPolicies{
Dynamic: map[core_model.ResourceType]xds.TypedMatchingPolicies{
api.MeshCircuitBreakerType: {
Type: api.MeshCircuitBreakerType,
ToRules: given.toRules,
},
},
}).
WithPolicies(xds_builders.MatchedPolicies().WithToPolicy(api.MeshCircuitBreakerType, given.toRules)).
Build()
for n, p := range core_plugins.Plugins().ProxyPlugins() {
Expect(p.Apply(context.Background(), xdsCtx.Mesh, proxy)).To(Succeed(), n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
core_plugins "github.com/kumahq/kuma/pkg/core/plugins"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
core_model "github.com/kumahq/kuma/pkg/core/resources/model"
core_xds "github.com/kumahq/kuma/pkg/core/xds"
core_rules "github.com/kumahq/kuma/pkg/plugins/policies/core/rules"
api "github.com/kumahq/kuma/pkg/plugins/policies/meshfaultinjection/api/v1alpha1"
Expand Down Expand Up @@ -65,14 +64,7 @@ var _ = Describe("MeshFaultInjection", func() {
WithService("frontend"),
),
).
WithPolicies(core_xds.MatchedPolicies{
Dynamic: map[core_model.ResourceType]core_xds.TypedMatchingPolicies{
api.MeshFaultInjectionType: {
Type: api.MeshFaultInjectionType,
FromRules: given.fromRules,
},
},
}).
WithPolicies(xds_builders.MatchedPolicies().WithFromPolicy(api.MeshFaultInjectionType, given.fromRules)).
Build()
plugin := plugin.NewPlugin().(core_plugins.PolicyPlugin)

Expand Down Expand Up @@ -239,14 +231,7 @@ var _ = Describe("MeshFaultInjection", func() {
xdsCtx := xds_samples.SampleContextWith(resources)
proxy := xds_builders.Proxy().
WithDataplane(samples.GatewayDataplaneBuilder()).
WithPolicies(core_xds.MatchedPolicies{
Dynamic: map[core_model.ResourceType]core_xds.TypedMatchingPolicies{
api.MeshFaultInjectionType: {
Type: api.MeshFaultInjectionType,
FromRules: fromRules,
},
},
}).
WithPolicies(xds_builders.MatchedPolicies().WithFromPolicy(api.MeshFaultInjectionType, fromRules)).
Build()
for n, p := range core_plugins.Plugins().ProxyPlugins() {
Expect(p.Apply(context.Background(), xdsCtx.Mesh, proxy)).To(Succeed(), n)
Expand Down
84 changes: 35 additions & 49 deletions pkg/plugins/policies/meshhealthcheck/plugin/v1alpha1/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
core_plugins "github.com/kumahq/kuma/pkg/core/plugins"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
core_model "github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/xds"
core_xds "github.com/kumahq/kuma/pkg/core/xds"
core_rules "github.com/kumahq/kuma/pkg/plugins/policies/core/rules"
api "github.com/kumahq/kuma/pkg/plugins/policies/meshhealthcheck/api/v1alpha1"
Expand Down Expand Up @@ -85,45 +83,40 @@ var _ = Describe("MeshHealthCheck", func() {

context := xds_samples.SampleContext()
proxy := xds_builders.Proxy().
WithDataplane(samples.DataplaneBackendBuilder().
AddOutbound(
builders.Outbound().WithAddress("127.0.0.1").WithPort(27777).WithTags(map[string]string{
mesh_proto.ServiceTag: httpServiceTag,
mesh_proto.ProtocolTag: "http",
}),
).
AddOutbound(
builders.Outbound().WithAddress("127.0.0.1").WithPort(27778).WithTags(map[string]string{
mesh_proto.ServiceTag: tcpServiceTag,
mesh_proto.ProtocolTag: "tcp",
}),
).
AddOutbound(
builders.Outbound().WithAddress("127.0.0.1").WithPort(27779).WithTags(map[string]string{
mesh_proto.ServiceTag: grpcServiceTag,
mesh_proto.ProtocolTag: "grpc",
}),
).
AddOutbound(
builders.Outbound().WithAddress("240.0.0.1").WithPort(27779).WithTags(map[string]string{
mesh_proto.ServiceTag: grpcServiceTag,
mesh_proto.ProtocolTag: "grpc",
}),
).
AddOutbound(
builders.Outbound().WithAddress("127.0.0.1").WithPort(27780).WithTags(map[string]string{
mesh_proto.ServiceTag: splitHttpServiceTag,
mesh_proto.ProtocolTag: "http",
}),
)).
WithPolicies(xds.MatchedPolicies{
Dynamic: map[core_model.ResourceType]xds.TypedMatchingPolicies{
api.MeshHealthCheckType: {
Type: api.MeshHealthCheckType,
ToRules: given.toRules,
},
},
}).
WithDataplane(
samples.DataplaneBackendBuilder().
AddOutbound(
builders.Outbound().WithAddress("127.0.0.1").WithPort(27777).WithTags(map[string]string{
mesh_proto.ServiceTag: httpServiceTag,
mesh_proto.ProtocolTag: "http",
}),
).
AddOutbound(
builders.Outbound().WithAddress("127.0.0.1").WithPort(27778).WithTags(map[string]string{
mesh_proto.ServiceTag: tcpServiceTag,
mesh_proto.ProtocolTag: "tcp",
}),
).
AddOutbound(
builders.Outbound().WithAddress("127.0.0.1").WithPort(27779).WithTags(map[string]string{
mesh_proto.ServiceTag: grpcServiceTag,
mesh_proto.ProtocolTag: "grpc",
}),
).
AddOutbound(
builders.Outbound().WithAddress("240.0.0.1").WithPort(27779).WithTags(map[string]string{
mesh_proto.ServiceTag: grpcServiceTag,
mesh_proto.ProtocolTag: "grpc",
}),
).
AddOutbound(
builders.Outbound().WithAddress("127.0.0.1").WithPort(27780).WithTags(map[string]string{
mesh_proto.ServiceTag: splitHttpServiceTag,
mesh_proto.ProtocolTag: "http",
}),
),
).
WithPolicies(xds_builders.MatchedPolicies().WithToPolicy(api.MeshHealthCheckType, given.toRules)).
WithRouting(
xds_builders.Routing().
WithOutboundTargets(
Expand Down Expand Up @@ -256,14 +249,7 @@ var _ = Describe("MeshHealthCheck", func() {
xdsCtx := xds_samples.SampleContextWith(resources)
proxy := xds_builders.Proxy().
WithDataplane(samples.GatewayDataplaneBuilder()).
WithPolicies(xds.MatchedPolicies{
Dynamic: map[core_model.ResourceType]xds.TypedMatchingPolicies{
api.MeshHealthCheckType: {
Type: api.MeshHealthCheckType,
ToRules: given.toRules,
},
},
}).
WithPolicies(xds_builders.MatchedPolicies().WithToPolicy(api.MeshHealthCheckType, given.toRules)).
Build()
for n, p := range core_plugins.Plugins().ProxyPlugins() {
Expect(p.Apply(context.Background(), xdsCtx.Mesh, proxy)).To(Succeed(), n)
Expand Down
Loading

0 comments on commit 13d6b34

Please sign in to comment.