Skip to content

Commit

Permalink
test: update for context in Generate signature
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont committed Jul 11, 2023
1 parent 44222dc commit 044d838
Show file tree
Hide file tree
Showing 31 changed files with 134 additions and 99 deletions.
2 changes: 1 addition & 1 deletion pkg/hds/tracker/healthcheck_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = Describe("HDS Snapshot generator", func() {
generator := NewSnapshotGenerator(resourceManager, given.hdsConfig, 9901)

// when
snapshot, err := generator.GenerateSnapshot(&envoy_config_core_v3.Node{Id: "mesh-1.dp-1"})
snapshot, err := generator.GenerateSnapshot(context.Background(), &envoy_config_core_v3.Node{Id: "mesh-1.dp-1"})

// then
Expect(err).ToNot(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1_test

import (
"context"
"fmt"
"path/filepath"
"strings"
Expand Down Expand Up @@ -986,7 +987,7 @@ var _ = Describe("MeshAccessLog", func() {
Items: given.routes,
}

context := test_xds.CreateSampleMeshContextWith(resources)
xdsCtx := test_xds.CreateSampleMeshContextWith(resources)
proxy := xds.Proxy{
APIVersion: "v3",
Dataplane: &core_mesh.DataplaneResource{
Expand Down Expand Up @@ -1017,11 +1018,11 @@ var _ = Describe("MeshAccessLog", func() {
}

gatewayGenerator := gateway_plugin.NewGenerator("test-zone")
generatedResources, err := gatewayGenerator.Generate(context, &proxy)
generatedResources, err := gatewayGenerator.Generate(context.Background(), xdsCtx, &proxy)
Expect(err).NotTo(HaveOccurred())

plugin := plugin.NewPlugin().(core_plugins.PolicyPlugin)
Expect(plugin.Apply(generatedResources, context, &proxy)).To(Succeed())
Expect(plugin.Apply(generatedResources, xdsCtx, &proxy)).To(Succeed())

nameSplit := strings.Split(GinkgoT().Name(), " ")
name := nameSplit[len(nameSplit)-1]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1_test

import (
"context"
"fmt"
"path/filepath"

Expand Down Expand Up @@ -418,7 +419,7 @@ var _ = Describe("MeshCircuitBreaker", func() {
Items: []*core_mesh.MeshGatewayRouteResource{samples.BackendGatewayRoute()},
}

context := test_xds.CreateSampleMeshContextWith(resources)
xdsCtx := test_xds.CreateSampleMeshContextWith(resources)
proxy := xds.Proxy{
APIVersion: "v3",
Dataplane: samples.GatewayDataplane(),
Expand All @@ -432,12 +433,12 @@ var _ = Describe("MeshCircuitBreaker", func() {
},
}
gatewayGenerator := gateway_plugin.NewGenerator("test-zone")
generatedResources, err := gatewayGenerator.Generate(context, &proxy)
generatedResources, err := gatewayGenerator.Generate(context.Background(), xdsCtx, &proxy)
Expect(err).NotTo(HaveOccurred())

// when
plugin := plugin.NewPlugin().(core_plugins.PolicyPlugin)
Expect(plugin.Apply(generatedResources, context, &proxy)).To(Succeed())
Expect(plugin.Apply(generatedResources, xdsCtx, &proxy)).To(Succeed())

getResourceYaml := func(list core_xds.ResourceList) []byte {
actualResource, err := util_proto.ToYAML(list[0].Resource)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1_test

import (
"context"
"path/filepath"

envoy_resource "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
Expand Down Expand Up @@ -204,7 +205,7 @@ var _ = Describe("MeshFaultInjection", func() {
Items: []*core_mesh.MeshGatewayRouteResource{samples.BackendGatewayRoute()},
}

context := test_xds.CreateSampleMeshContextWith(resources)
xdsCtx := test_xds.CreateSampleMeshContextWith(resources)
proxy := core_xds.Proxy{
APIVersion: "v3",
Dataplane: samples.GatewayDataplane(),
Expand All @@ -218,14 +219,14 @@ var _ = Describe("MeshFaultInjection", func() {
},
}
gatewayGenerator := gatewayGenerator()
generatedResources, err := gatewayGenerator.Generate(context, &proxy)
generatedResources, err := gatewayGenerator.Generate(context.Background(), xdsCtx, &proxy)
Expect(err).NotTo(HaveOccurred())

// when
plugin := plugin.NewPlugin().(core_plugins.PolicyPlugin)

// then
Expect(plugin.Apply(generatedResources, context, &proxy)).To(Succeed())
Expect(plugin.Apply(generatedResources, xdsCtx, &proxy)).To(Succeed())
Expect(util_proto.ToYAML(generatedResources.ListOf(envoy_resource.ListenerType)[0].Resource)).To(test_matchers.MatchGoldenYAML(filepath.Join("testdata", "gateway_basic_listener.golden.yaml")))
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1_test

import (
"context"
"fmt"
"path/filepath"

Expand Down Expand Up @@ -267,7 +268,7 @@ var _ = Describe("MeshHealthCheck", func() {
Items: []*core_mesh.MeshGatewayRouteResource{samples.BackendGatewayRoute()},
}

context := test_xds.CreateSampleMeshContextWith(resources)
xdsCtx := test_xds.CreateSampleMeshContextWith(resources)
proxy := xds.Proxy{
APIVersion: "v3",
Dataplane: samples.GatewayDataplane(),
Expand All @@ -281,12 +282,12 @@ var _ = Describe("MeshHealthCheck", func() {
},
}
gatewayGenerator := gateway_plugin.NewGenerator("test-zone")
generatedResources, err := gatewayGenerator.Generate(context, &proxy)
generatedResources, err := gatewayGenerator.Generate(context.Background(), xdsCtx, &proxy)
Expect(err).NotTo(HaveOccurred())

// when
plugin := plugin.NewPlugin().(core_plugins.PolicyPlugin)
Expect(plugin.Apply(generatedResources, context, &proxy)).To(Succeed())
Expect(plugin.Apply(generatedResources, xdsCtx, &proxy)).To(Succeed())

getResourceYaml := func(list core_xds.ResourceList) []byte {
actualResource, err := util_proto.ToYAML(list[0].Resource)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1_test

import (
"context"
"fmt"
"path/filepath"
"strings"
Expand Down Expand Up @@ -378,7 +379,7 @@ var _ = Describe("MeshLoadBalancingStrategy", func() {
Items: []*core_mesh.MeshGatewayRouteResource{samples.BackendGatewayRoute()},
}

context := test_xds.CreateSampleMeshContextWith(resources)
xdsCtx := test_xds.CreateSampleMeshContextWith(resources)
proxy := core_xds.Proxy{
APIVersion: "v3",
Dataplane: samples.GatewayDataplane(),
Expand All @@ -392,12 +393,12 @@ var _ = Describe("MeshLoadBalancingStrategy", func() {
},
}
gatewayGenerator := gateway_plugin.NewGenerator("test-zone")
generatedResources, err := gatewayGenerator.Generate(context, &proxy)
generatedResources, err := gatewayGenerator.Generate(context.Background(), xdsCtx, &proxy)
Expect(err).NotTo(HaveOccurred())

// when
plugin := plugin.NewPlugin().(core_plugins.PolicyPlugin)
Expect(plugin.Apply(generatedResources, context, &proxy)).To(Succeed())
Expect(plugin.Apply(generatedResources, xdsCtx, &proxy)).To(Succeed())

getResourceYaml := func(list core_xds.ResourceList) []byte {
actualResource, err := util_proto.ToYAML(list[0].Resource)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1_test

import (
"context"
"path/filepath"
"time"

Expand Down Expand Up @@ -453,7 +454,7 @@ var _ = Describe("MeshRateLimit", func() {
Items: []*core_mesh.MeshGatewayRouteResource{samples.BackendGatewayRoute()},
}

context := test_xds.CreateSampleMeshContextWith(resources)
xdsCtx := test_xds.CreateSampleMeshContextWith(resources)
proxy := xds.Proxy{
APIVersion: "v3",
Dataplane: samples.GatewayDataplane(),
Expand All @@ -467,14 +468,14 @@ var _ = Describe("MeshRateLimit", func() {
},
}
gatewayGenerator := gatewayGenerator()
generatedResources, err := gatewayGenerator.Generate(context, &proxy)
generatedResources, err := gatewayGenerator.Generate(context.Background(), xdsCtx, &proxy)
Expect(err).NotTo(HaveOccurred())

// when
plugin := plugin.NewPlugin().(core_plugins.PolicyPlugin)

// then
Expect(plugin.Apply(generatedResources, context, &proxy)).To(Succeed())
Expect(plugin.Apply(generatedResources, xdsCtx, &proxy)).To(Succeed())
Expect(util_proto.ToYAML(generatedResources.ListOf(envoy_resource.RouteType)[0].Resource)).To(test_matchers.MatchGoldenYAML(filepath.Join("testdata", "gateway_basic_routes.golden.yaml")))
Expect(util_proto.ToYAML(generatedResources.ListOf(envoy_resource.ListenerType)[0].Resource)).To(test_matchers.MatchGoldenYAML(filepath.Join("testdata", "gateway_basic_listener.golden.yaml")))
})
Expand Down
7 changes: 4 additions & 3 deletions pkg/plugins/policies/meshretry/plugin/v1alpha1/plugin_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1_test

import (
"context"
"fmt"
"path/filepath"
"time"
Expand Down Expand Up @@ -317,7 +318,7 @@ var _ = Describe("MeshRetry", func() {
Items: given.gatewayRoutes,
}

context := test_xds.CreateSampleMeshContextWith(resources)
xdsCtx := test_xds.CreateSampleMeshContextWith(resources)
proxy := xds.Proxy{
APIVersion: "v3",
Dataplane: samples.GatewayDataplane(),
Expand All @@ -331,12 +332,12 @@ var _ = Describe("MeshRetry", func() {
},
}
gatewayGenerator := gateway_plugin.NewGenerator("test-zone")
generatedResources, err := gatewayGenerator.Generate(context, &proxy)
generatedResources, err := gatewayGenerator.Generate(context.Background(), xdsCtx, &proxy)
Expect(err).NotTo(HaveOccurred())

// when
plugin := plugin_v1alpha1.NewPlugin().(core_plugins.PolicyPlugin)
Expect(plugin.Apply(generatedResources, context, &proxy)).To(Succeed())
Expect(plugin.Apply(generatedResources, xdsCtx, &proxy)).To(Succeed())

// then
Expect(getResourceYaml(generatedResources.ListOf(envoy_resource.ListenerType))).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"context"
"fmt"
"path/filepath"
"strings"
Expand Down Expand Up @@ -433,7 +434,7 @@ var _ = Describe("MeshTimeout", func() {
Items: append([]*core_mesh.MeshGatewayRouteResource{samples.BackendGatewayRoute()}, given.routes...),
}

context := test_xds.CreateSampleMeshContextWith(resources)
xdsCtx := test_xds.CreateSampleMeshContextWith(resources)
proxy := xds.Proxy{
APIVersion: "v3",
Dataplane: samples.GatewayDataplane(),
Expand Down Expand Up @@ -461,12 +462,12 @@ var _ = Describe("MeshTimeout", func() {
},
}
gatewayGenerator := gateway_plugin.NewGenerator("test-zone")
generatedResources, err := gatewayGenerator.Generate(context, &proxy)
generatedResources, err := gatewayGenerator.Generate(context.Background(), xdsCtx, &proxy)
Expect(err).NotTo(HaveOccurred())

// when
plugin := NewPlugin().(core_plugins.PolicyPlugin)
Expect(plugin.Apply(generatedResources, context, &proxy)).To(Succeed())
Expect(plugin.Apply(generatedResources, xdsCtx, &proxy)).To(Succeed())

nameSplit := strings.Split(GinkgoT().Name(), " ")
name := nameSplit[len(nameSplit)-1]
Expand Down
10 changes: 6 additions & 4 deletions pkg/plugins/runtime/gateway/gateway_route_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ var _ = Describe("Gateway Route", func() {

// We expect there to be a Dataplane fixture named
// "default" in the current mesh.
ctx, proxy := MakeGeneratorContext(rt,
core_model.ResourceKey{Mesh: "default", Name: "default"})
xdsCtx, proxy := MakeGeneratorContext(
rt,
core_model.ResourceKey{Mesh: "default", Name: "default"},
)

// Tokens for zone egress needs to be generated
// Without test configuration each run will generates
// new tokens for authentication.
ctx.ControlPlane.Secrets = &xds.TestSecrets{}
xdsCtx.ControlPlane.Secrets = &xds.TestSecrets{}

Expect(proxy.Dataplane.Spec.IsBuiltinGateway()).To(BeTrue())

if _, err := reconciler.Reconcile(*ctx, proxy); err != nil {
if _, err := reconciler.Reconcile(context.Background(), *xdsCtx, proxy); err != nil {
return nil, err
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/plugins/runtime/gateway/listener_generator_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gateway_test

import (
"context"
"path"

"github.com/envoyproxy/go-control-plane/pkg/cache/v3"
Expand Down Expand Up @@ -36,12 +37,12 @@ var _ = Describe("Gateway Listener", func() {

// We expect there to be a Dataplane fixture named
// "default" in the current mesh.
ctx, proxy := MakeGeneratorContext(rt,
xdsCtx, proxy := MakeGeneratorContext(rt,
core_model.ResourceKey{Mesh: r.GetMeta().GetMesh(), Name: "default"})

Expect(proxy.Dataplane.Spec.IsBuiltinGateway()).To(BeTrue())

if _, err := reconciler.Reconcile(*ctx, proxy); err != nil {
if _, err := reconciler.Reconcile(context.Background(), *xdsCtx, proxy); err != nil {
return nil, err
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/test/xds/secrets.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xds

import (
"context"
"time"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
Expand Down Expand Up @@ -64,6 +65,7 @@ func (ts *TestSecrets) get(meshes []*core_mesh.MeshResource) (*core_xds.Identity
}

func (ts *TestSecrets) GetForZoneEgress(
_ context.Context,
_ *core_mesh.ZoneEgressResource,
mesh *core_mesh.MeshResource,
) (*core_xds.IdentitySecret, *core_xds.CaSecret, error) {
Expand All @@ -73,6 +75,7 @@ func (ts *TestSecrets) GetForZoneEgress(
}

func (ts *TestSecrets) GetForDataPlane(
_ context.Context,
_ *core_mesh.DataplaneResource,
mesh *core_mesh.MeshResource,
meshes []*core_mesh.MeshResource,
Expand All @@ -82,6 +85,7 @@ func (ts *TestSecrets) GetForDataPlane(
}

func (ts *TestSecrets) GetAllInOne(
_ context.Context,
mesh *core_mesh.MeshResource,
_ *core_mesh.DataplaneResource,
meshes []*core_mesh.MeshResource,
Expand Down
7 changes: 4 additions & 3 deletions pkg/util/watchdog/watchdog_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package watchdog_test

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -37,7 +38,7 @@ var _ = Describe("SimpleWatchdog", func() {
C: timeTicks,
}
},
OnTick: func() error {
OnTick: func(context.Context) error {
onTickCalls <- struct{}{}
return nil
},
Expand Down Expand Up @@ -82,7 +83,7 @@ var _ = Describe("SimpleWatchdog", func() {
C: timeTicks,
}
},
OnTick: func() error {
OnTick: func(context.Context) error {
return expectedErr
},
OnError: func(err error) {
Expand Down Expand Up @@ -121,7 +122,7 @@ var _ = Describe("SimpleWatchdog", func() {
C: timeTicks,
}
},
OnTick: func() error {
OnTick: func(context.Context) error {
panic("xyz")
},
OnError: func(err error) {
Expand Down
Loading

0 comments on commit 044d838

Please sign in to comment.