From 366c1acf3129bce126923d2dd577c270d3aabb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Sat, 7 Dec 2024 01:04:22 +0100 Subject: [PATCH] refactor: restructure processors (#2199) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- pkg/runner/mocks/registry.go | 23 +++ pkg/runner/processors/context.go | 94 +++++----- pkg/runner/processors/mocks.go | 23 --- pkg/runner/processors/step.go | 182 +++++++++---------- pkg/runner/processors/step_test.go | 5 +- pkg/runner/processors/test.go | 177 ------------------- pkg/runner/processors/tests.go | 132 -------------- pkg/runner/run.go | 7 +- pkg/runner/test.go | 202 ++++++++++++++++++++++ pkg/runner/{processors => }/test_test.go | 18 +- pkg/runner/tests.go | 75 ++++++++ pkg/runner/{processors => }/tests_test.go | 25 +-- 12 files changed, 462 insertions(+), 501 deletions(-) create mode 100644 pkg/runner/mocks/registry.go delete mode 100644 pkg/runner/processors/mocks.go delete mode 100644 pkg/runner/processors/test.go delete mode 100644 pkg/runner/processors/tests.go create mode 100644 pkg/runner/test.go rename pkg/runner/{processors => }/test_test.go (95%) create mode 100644 pkg/runner/tests.go rename pkg/runner/{processors => }/tests_test.go (90%) diff --git a/pkg/runner/mocks/registry.go b/pkg/runner/mocks/registry.go new file mode 100644 index 000000000..901a0e806 --- /dev/null +++ b/pkg/runner/mocks/registry.go @@ -0,0 +1,23 @@ +package mocks + +import ( + "github.com/kyverno/chainsaw/pkg/client" + "github.com/kyverno/chainsaw/pkg/engine/clusters" + "k8s.io/client-go/rest" +) + +type Registry struct { + Client client.Client +} + +func (r Registry) Register(string, clusters.Cluster) clusters.Registry { + return r +} + +func (r Registry) Lookup(string) clusters.Cluster { + return nil +} + +func (r Registry) Build(clusters.Cluster) (*rest.Config, client.Client, error) { + return nil, r.Client, nil +} diff --git a/pkg/runner/processors/context.go b/pkg/runner/processors/context.go index 9bca130aa..b037c6902 100644 --- a/pkg/runner/processors/context.go +++ b/pkg/runner/processors/context.go @@ -17,55 +17,55 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -type namespaceData struct { - cleaner cleaner.CleanerCollector - compilers compilers.Compilers - name string - template *v1alpha1.Projection +type NamespaceData struct { + Cleaner cleaner.CleanerCollector + Compilers compilers.Compilers + Name string + Template *v1alpha1.Projection } -type contextData struct { - basePath string - catch []v1alpha1.CatchFinally - cluster *string - clusters v1alpha1.Clusters - delayBeforeCleanup *metav1.Duration - deletionPropagation *metav1.DeletionPropagation - dryRun *bool - skipDelete *bool - templating *bool - terminationGrace *metav1.Duration - timeouts *v1alpha1.Timeouts +type ContextData struct { + BasePath string + Catch []v1alpha1.CatchFinally + Cluster *string + Clusters v1alpha1.Clusters + DelayBeforeCleanup *metav1.Duration + DeletionPropagation *metav1.DeletionPropagation + DryRun *bool + SkipDelete *bool + Templating *bool + TerminationGrace *metav1.Duration + Timeouts *v1alpha1.Timeouts } -func setupContext(ctx context.Context, tc engine.Context, data contextData) (engine.Context, error) { - if len(data.catch) > 0 { - tc = tc.WithCatch(ctx, data.catch...) +func SetupContext(ctx context.Context, tc engine.Context, data ContextData) (engine.Context, error) { + if len(data.Catch) > 0 { + tc = tc.WithCatch(ctx, data.Catch...) } - if data.dryRun != nil { - tc = tc.WithDryRun(ctx, *data.dryRun) + if data.DryRun != nil { + tc = tc.WithDryRun(ctx, *data.DryRun) } - if data.delayBeforeCleanup != nil { - tc = tc.WithDelayBeforeCleanup(ctx, &data.delayBeforeCleanup.Duration) + if data.DelayBeforeCleanup != nil { + tc = tc.WithDelayBeforeCleanup(ctx, &data.DelayBeforeCleanup.Duration) } - if data.deletionPropagation != nil { - tc = tc.WithDeletionPropagation(ctx, *data.deletionPropagation) + if data.DeletionPropagation != nil { + tc = tc.WithDeletionPropagation(ctx, *data.DeletionPropagation) } - if data.skipDelete != nil { - tc = tc.WithSkipDelete(ctx, *data.skipDelete) + if data.SkipDelete != nil { + tc = tc.WithSkipDelete(ctx, *data.SkipDelete) } - if data.templating != nil { - tc = tc.WithTemplating(ctx, *data.templating) + if data.Templating != nil { + tc = tc.WithTemplating(ctx, *data.Templating) } - if data.terminationGrace != nil { - tc = tc.WithTerminationGrace(ctx, &data.terminationGrace.Duration) + if data.TerminationGrace != nil { + tc = tc.WithTerminationGrace(ctx, &data.TerminationGrace.Duration) } - if data.timeouts != nil { - tc = tc.WithTimeouts(ctx, *data.timeouts) + if data.Timeouts != nil { + tc = tc.WithTimeouts(ctx, *data.Timeouts) } - tc = engine.WithClusters(ctx, tc, data.basePath, data.clusters) - if data.cluster != nil { - if _tc, err := engine.WithCurrentCluster(ctx, tc, *data.cluster); err != nil { + tc = engine.WithClusters(ctx, tc, data.BasePath, data.Clusters) + if data.Cluster != nil { + if _tc, err := engine.WithCurrentCluster(ctx, tc, *data.Cluster); err != nil { return tc, err } else { tc = _tc @@ -74,9 +74,9 @@ func setupContext(ctx context.Context, tc engine.Context, data contextData) (eng return tc, nil } -func setupNamespace(ctx context.Context, tc engine.Context, data namespaceData) (engine.Context, *corev1.Namespace, error) { +func SetupNamespace(ctx context.Context, tc engine.Context, data NamespaceData) (engine.Context, *corev1.Namespace, error) { var ns *corev1.Namespace - if namespace, err := buildNamespace(ctx, data.compilers, data.name, data.template, tc.Bindings()); err != nil { + if namespace, err := buildNamespace(ctx, data.Compilers, data.Name, data.Template, tc.Bindings()); err != nil { return tc, nil, err } else if _, clusterClient, err := tc.CurrentClusterClient(); err != nil { return tc, nil, err @@ -86,8 +86,8 @@ func setupNamespace(ctx context.Context, tc engine.Context, data namespaceData) return tc, nil, err } else if err := clusterClient.Create(ctx, namespace.DeepCopy()); err != nil { return tc, nil, err - } else if data.cleaner != nil { - data.cleaner.Add(clusterClient, namespace) + } else if data.Cleaner != nil { + data.Cleaner.Add(clusterClient, namespace) } } ns = namespace @@ -98,7 +98,7 @@ func setupNamespace(ctx context.Context, tc engine.Context, data namespaceData) return tc, ns, nil } -func setupBindings(ctx context.Context, tc engine.Context, bindings ...v1alpha1.Binding) (engine.Context, error) { +func SetupBindings(ctx context.Context, tc engine.Context, bindings ...v1alpha1.Binding) (engine.Context, error) { if _tc, err := engine.WithBindings(ctx, tc, bindings...); err != nil { return tc, err } else { @@ -107,8 +107,8 @@ func setupBindings(ctx context.Context, tc engine.Context, bindings ...v1alpha1. return tc, nil } -func setupCleanup(ctx context.Context, tc engine.Context) cleaner.CleanerCollector { - if !tc.SkipDelete() { +func SetupCleanup(ctx context.Context, tc engine.Context) cleaner.CleanerCollector { + if tc.SkipDelete() { return nil } t := testing.FromContext(ctx) @@ -128,10 +128,10 @@ func setupCleanup(ctx context.Context, tc engine.Context) cleaner.CleanerCollect return cleaner } -func setupContextAndBindings(ctx context.Context, tc engine.Context, data contextData, bindings ...v1alpha1.Binding) (engine.Context, error) { - if tc, err := setupContext(ctx, tc, data); err != nil { +func setupContextAndBindings(ctx context.Context, tc engine.Context, data ContextData, bindings ...v1alpha1.Binding) (engine.Context, error) { + if tc, err := SetupContext(ctx, tc, data); err != nil { return tc, err } else { - return setupBindings(ctx, tc, bindings...) + return SetupBindings(ctx, tc, bindings...) } } diff --git a/pkg/runner/processors/mocks.go b/pkg/runner/processors/mocks.go deleted file mode 100644 index 8a7ec079a..000000000 --- a/pkg/runner/processors/mocks.go +++ /dev/null @@ -1,23 +0,0 @@ -package processors - -import ( - "github.com/kyverno/chainsaw/pkg/client" - "github.com/kyverno/chainsaw/pkg/engine/clusters" - "k8s.io/client-go/rest" -) - -type registryMock struct { - client client.Client -} - -func (r registryMock) Register(string, clusters.Cluster) clusters.Registry { - return r -} - -func (r registryMock) Lookup(string) clusters.Cluster { - return nil -} - -func (r registryMock) Build(clusters.Cluster) (*rest.Config, client.Client, error) { - return nil, r.client, nil -} diff --git a/pkg/runner/processors/step.go b/pkg/runner/processors/step.go index 3302641f8..54bf57a22 100644 --- a/pkg/runner/processors/step.go +++ b/pkg/runner/processors/step.go @@ -73,15 +73,15 @@ func (p *stepProcessor) Run(ctx context.Context, namespacer namespacer.Namespace if p.step.Compiler != nil { tc = tc.WithDefaultCompiler(string(*p.step.Compiler)) } - contextData := contextData{ - basePath: p.basePath, - catch: p.step.Catch, - cluster: p.step.Cluster, - clusters: p.step.Clusters, - deletionPropagation: p.step.DeletionPropagationPolicy, - skipDelete: p.step.SkipDelete, - templating: p.step.Template, - timeouts: p.step.Timeouts, + contextData := ContextData{ + BasePath: p.basePath, + Catch: p.step.Catch, + Cluster: p.step.Cluster, + Clusters: p.step.Clusters, + DeletionPropagation: p.step.DeletionPropagationPolicy, + SkipDelete: p.step.SkipDelete, + Templating: p.step.Template, + Timeouts: p.step.Timeouts, } tc, err := setupContextAndBindings(ctx, tc, contextData, p.step.Bindings...) if err != nil { @@ -392,13 +392,13 @@ func (p *stepProcessor) applyOperation(compilers compilers.Compilers, id int, na }, model.OperationTypeApply, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - dryRun: op.DryRun, - templating: op.Template, - timeouts: &v1alpha1.Timeouts{Apply: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + DryRun: op.DryRun, + Templating: op.Template, + Timeouts: &v1alpha1.Timeouts{Apply: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData, op.Bindings...); err != nil { return nil, nil, tc, err @@ -440,12 +440,12 @@ func (p *stepProcessor) assertOperation(compilers compilers.Compilers, id int, n }, model.OperationTypeAssert, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - templating: op.Template, - timeouts: &v1alpha1.Timeouts{Assert: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + Templating: op.Template, + Timeouts: &v1alpha1.Timeouts{Assert: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData, op.Bindings...); err != nil { return nil, nil, tc, err @@ -478,11 +478,11 @@ func (p *stepProcessor) commandOperation(_ compilers.Compilers, id int, namespac }, model.OperationTypeCommand, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + Timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData, op.Bindings...); err != nil { return nil, nil, tc, err @@ -517,13 +517,13 @@ func (p *stepProcessor) createOperation(compilers compilers.Compilers, id int, n }, model.OperationTypeCreate, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - dryRun: op.DryRun, - templating: op.Template, - timeouts: &v1alpha1.Timeouts{Apply: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + DryRun: op.DryRun, + Templating: op.Template, + Timeouts: &v1alpha1.Timeouts{Apply: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData, op.Bindings...); err != nil { return nil, nil, tc, err @@ -579,13 +579,13 @@ func (p *stepProcessor) deleteOperation(compilers compilers.Compilers, id int, n }, model.OperationTypeDelete, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - deletionPropagation: op.DeletionPropagationPolicy, - templating: op.Template, - timeouts: &v1alpha1.Timeouts{Delete: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + DeletionPropagation: op.DeletionPropagationPolicy, + Templating: op.Template, + Timeouts: &v1alpha1.Timeouts{Delete: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData, op.Bindings...); err != nil { return nil, nil, tc, err @@ -620,11 +620,11 @@ func (p *stepProcessor) describeOperation(_ compilers.Compilers, id int, namespa }, model.OperationTypeCommand, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + Timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData); err != nil { return nil, nil, tc, err @@ -668,12 +668,12 @@ func (p *stepProcessor) errorOperation(compilers compilers.Compilers, id int, na }, model.OperationTypeError, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - templating: op.Template, - timeouts: &v1alpha1.Timeouts{Error: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + Templating: op.Template, + Timeouts: &v1alpha1.Timeouts{Error: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData, op.Bindings...); err != nil { return nil, nil, tc, err @@ -706,11 +706,11 @@ func (p *stepProcessor) getOperation(_ compilers.Compilers, id int, namespacer n }, model.OperationTypeCommand, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + Timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData); err != nil { return nil, nil, tc, err @@ -750,11 +750,11 @@ func (p *stepProcessor) logsOperation(_ compilers.Compilers, id int, namespacer }, model.OperationTypeCommand, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + Timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData); err != nil { return nil, nil, tc, err @@ -798,13 +798,13 @@ func (p *stepProcessor) patchOperation(compilers compilers.Compilers, id int, na }, model.OperationTypePatch, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - dryRun: op.DryRun, - templating: op.Template, - timeouts: &v1alpha1.Timeouts{Apply: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + DryRun: op.DryRun, + Templating: op.Template, + Timeouts: &v1alpha1.Timeouts{Apply: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData, op.Bindings...); err != nil { return nil, nil, tc, err @@ -841,11 +841,11 @@ func (p *stepProcessor) proxyOperation(_ compilers.Compilers, id int, namespacer }, model.OperationTypeCommand, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + Timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData); err != nil { return nil, nil, tc, err @@ -885,11 +885,11 @@ func (p *stepProcessor) scriptOperation(_ compilers.Compilers, id int, namespace }, model.OperationTypeScript, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + Timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData, op.Bindings...); err != nil { return nil, nil, tc, err @@ -936,13 +936,13 @@ func (p *stepProcessor) updateOperation(compilers compilers.Compilers, id int, n }, model.OperationTypeUpdate, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - dryRun: op.DryRun, - templating: op.Template, - timeouts: &v1alpha1.Timeouts{Apply: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + DryRun: op.DryRun, + Templating: op.Template, + Timeouts: &v1alpha1.Timeouts{Apply: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData, op.Bindings...); err != nil { return nil, nil, tc, err @@ -979,11 +979,11 @@ func (p *stepProcessor) waitOperation(_ compilers.Compilers, id int, namespacer }, model.OperationTypeCommand, func(ctx context.Context, tc engine.Context) (operations.Operation, *time.Duration, engine.Context, error) { - contextData := contextData{ - basePath: p.basePath, - cluster: op.Cluster, - clusters: op.Clusters, - timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, + contextData := ContextData{ + BasePath: p.basePath, + Cluster: op.Cluster, + Clusters: op.Clusters, + Timeouts: &v1alpha1.Timeouts{Exec: op.Timeout}, } if tc, err := setupContextAndBindings(ctx, tc, contextData); err != nil { return nil, nil, tc, err diff --git a/pkg/runner/processors/step_test.go b/pkg/runner/processors/step_test.go index abe7b15c4..078e34531 100644 --- a/pkg/runner/processors/step_test.go +++ b/pkg/runner/processors/step_test.go @@ -15,6 +15,7 @@ import ( fakeNamespacer "github.com/kyverno/chainsaw/pkg/engine/namespacer/testing" "github.com/kyverno/chainsaw/pkg/loaders/config" "github.com/kyverno/chainsaw/pkg/model" + "github.com/kyverno/chainsaw/pkg/runner/mocks" "github.com/kyverno/chainsaw/pkg/testing" "github.com/stretchr/testify/assert" kerror "k8s.io/apimachinery/pkg/api/errors" @@ -778,9 +779,9 @@ func TestStepProcessor_Run(t *testing.T) { }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - registry := registryMock{} + registry := mocks.Registry{} if tc.client != nil { - registry.client = tc.client + registry.Client = tc.client } stepProcessor := NewStepProcessor( tc.stepSpec, diff --git a/pkg/runner/processors/test.go b/pkg/runner/processors/test.go deleted file mode 100644 index eeb6d5fdb..000000000 --- a/pkg/runner/processors/test.go +++ /dev/null @@ -1,177 +0,0 @@ -package processors - -import ( - "context" - "fmt" - "time" - - petname "github.com/dustinkirkland/golang-petname" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" - "github.com/kyverno/chainsaw/pkg/cleanup/cleaner" - "github.com/kyverno/chainsaw/pkg/discovery" - "github.com/kyverno/chainsaw/pkg/engine" - "github.com/kyverno/chainsaw/pkg/engine/logging" - "github.com/kyverno/chainsaw/pkg/engine/namespacer" - "github.com/kyverno/chainsaw/pkg/model" - "github.com/kyverno/chainsaw/pkg/runner/failer" - "github.com/kyverno/chainsaw/pkg/testing" - "github.com/kyverno/pkg/ext/output/color" - "k8s.io/utils/clock" -) - -type TestProcessor interface { - Run(context.Context, namespacer.Namespacer, engine.Context) -} - -func NewTestProcessor( - test discovery.Test, - size int, - clock clock.PassiveClock, - nsTemplate *v1alpha1.Projection, - nsTemplateCompiler *v1alpha1.Compiler, -) TestProcessor { - if template := test.Test.Spec.NamespaceTemplate; template != nil && template.Value() != nil { - nsTemplate = template - nsTemplateCompiler = test.Test.Spec.NamespaceTemplateCompiler - } - return &testProcessor{ - test: test, - size: size, - clock: clock, - nsTemplate: nsTemplate, - nsTemplateCompiler: nsTemplateCompiler, - } -} - -type testProcessor struct { - test discovery.Test - size int - clock clock.PassiveClock - nsTemplate *v1alpha1.Projection - nsTemplateCompiler *v1alpha1.Compiler -} - -func (p *testProcessor) Run(ctx context.Context, nspacer namespacer.Namespacer, tc engine.Context) { - t := testing.FromContext(ctx) - // setup reporting - report := &model.TestReport{ - BasePath: p.test.BasePath, - Name: p.test.Test.Name, - Concurrent: p.test.Test.Spec.Concurrent, - StartTime: time.Now(), - } - stepReport := &model.StepReport{ - Name: "main", - StartTime: time.Now(), - } - t.Cleanup(func() { - report.EndTime = time.Now() - if t.Skipped() { - report.Skipped = true - } - tc.Report.Add(report) - }) - // setup context - contextData := contextData{ - basePath: p.test.BasePath, - catch: p.test.Test.Spec.Catch, - cluster: p.test.Test.Spec.Cluster, - clusters: p.test.Test.Spec.Clusters, - delayBeforeCleanup: p.test.Test.Spec.DelayBeforeCleanup, - deletionPropagation: p.test.Test.Spec.DeletionPropagationPolicy, - skipDelete: p.test.Test.Spec.SkipDelete, - templating: p.test.Test.Spec.Template, - terminationGrace: p.test.Test.Spec.ForceTerminationGracePeriod, - timeouts: p.test.Test.Spec.Timeouts, - } - tc, err := setupContext(ctx, tc, contextData) - if err != nil { - logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) - failer.FailNow(ctx) - } - timeouts := tc.Timeouts() - mainCleaner := cleaner.New(timeouts.Cleanup.Duration, nil, tc.DeletionPropagation()) - t.Cleanup(func() { - if !mainCleaner.Empty() { - logging.Log(ctx, logging.Cleanup, logging.BeginStatus, color.BoldFgCyan) - defer func() { - logging.Log(ctx, logging.Cleanup, logging.EndStatus, color.BoldFgCyan) - }() - stepReport := &model.StepReport{ - Name: fmt.Sprintf("cleanup (%s)", stepReport.Name), - StartTime: time.Now(), - } - defer func() { - stepReport.EndTime = time.Now() - report.Add(stepReport) - }() - for _, err := range mainCleaner.Run(ctx, stepReport) { - logging.Log(ctx, logging.Cleanup, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) - failer.Fail(ctx) - } - } - }) - // setup namespace - // TODO: should be part of setupContext ? - if p.test.Test.Spec.Compiler != nil { - tc = tc.WithDefaultCompiler(string(*p.test.Test.Spec.Compiler)) - } - nsName := p.test.Test.Spec.Namespace - if nspacer == nil && nsName == "" { - nsName = fmt.Sprintf("chainsaw-%s", petname.Generate(2, "-")) - } - if nsName != "" { - var nsCleaner cleaner.CleanerCollector - if !tc.SkipDelete() { - nsCleaner = mainCleaner - } - // TODO: this may not use the right default compiler if the template is coming from the config - // but the default compiler is specified at the test level - compilers := tc.Compilers() - if p.nsTemplateCompiler != nil { - compilers = compilers.WithDefaultCompiler(string(*p.nsTemplateCompiler)) - } - namespaceData := namespaceData{ - cleaner: nsCleaner, - compilers: compilers, - name: nsName, - template: p.nsTemplate, - } - nsTc, namespace, err := setupNamespace(ctx, tc, namespaceData) - if err != nil { - logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) - failer.FailNow(ctx) - } - tc = nsTc - if namespace != nil { - nspacer = namespacer.New(namespace.GetName()) - } - } - if nspacer != nil { - report.Namespace = nspacer.GetNamespace() - } - // setup bindings - tc, err = setupBindings(ctx, tc, p.test.Test.Spec.Bindings...) - if err != nil { - logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) - failer.FailNow(ctx) - } - // run steps - for i, step := range p.test.Test.Spec.Steps { - name := step.Name - if name == "" { - name = fmt.Sprintf("step-%d", i+1) - } - ctx := logging.IntoContext(ctx, logging.NewLogger(t, p.clock, p.test.Test.Name, fmt.Sprintf("%-*s", p.size, name))) - info := StepInfo{ - Id: i + 1, - } - tc := tc.WithBinding(ctx, "step", info) - processor := p.createStepProcessor(step, report) - processor.Run(ctx, nspacer, tc) - } -} - -func (p *testProcessor) createStepProcessor(step v1alpha1.TestStep, report *model.TestReport) StepProcessor { - return NewStepProcessor(step, report, p.test.BasePath) -} diff --git a/pkg/runner/processors/tests.go b/pkg/runner/processors/tests.go deleted file mode 100644 index 70edb751f..000000000 --- a/pkg/runner/processors/tests.go +++ /dev/null @@ -1,132 +0,0 @@ -package processors - -import ( - "context" - "fmt" - - "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" - "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" - "github.com/kyverno/chainsaw/pkg/discovery" - "github.com/kyverno/chainsaw/pkg/engine" - "github.com/kyverno/chainsaw/pkg/engine/logging" - "github.com/kyverno/chainsaw/pkg/engine/namespacer" - "github.com/kyverno/chainsaw/pkg/runner/failer" - "github.com/kyverno/chainsaw/pkg/runner/names" - "github.com/kyverno/chainsaw/pkg/testing" - "github.com/kyverno/pkg/ext/output/color" - "k8s.io/utils/clock" -) - -func RunTests(ctx context.Context, clock clock.PassiveClock, nsOptions v1alpha2.NamespaceOptions, tc engine.Context, tests ...discovery.Test) { - t := testing.FromContext(ctx) - // setup cleaner - cleaner := setupCleanup(ctx, tc) - // setup namespace - var nspacer namespacer.Namespacer - if nsOptions.Name != "" { - compilers := tc.Compilers() - if nsOptions.Compiler != nil { - compilers = compilers.WithDefaultCompiler(string(*nsOptions.Compiler)) - } - namespaceData := namespaceData{ - cleaner: cleaner, - compilers: compilers, - name: nsOptions.Name, - template: nsOptions.Template, - } - nsTc, namespace, err := setupNamespace(ctx, tc, namespaceData) - if err != nil { - logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) - tc.IncFailed() - failer.FailNow(ctx) - } - tc = nsTc - if namespace != nil { - nspacer = namespacer.New(namespace.GetName()) - } - } - // loop through tests - for i := range tests { - test := tests[i] - name, err := names.Test(tc.FullName(), test) - if err != nil { - logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) - tc.IncFailed() - failer.FailNow(ctx) - } - // compute test scenarios - scenarios := []v1alpha1.Scenario{{}} - if test.Test == nil { - scenarios = nil - } else if len(test.Test.Spec.Scenarios) != 0 { - scenarios = test.Test.Spec.Scenarios - } - // loop through test scenarios - for s := range scenarios { - // run each test scenario in a separate T - t.Run(name, func(t *testing.T) { - t.Helper() - tc, err := engine.WithBindings(ctx, tc, scenarios[s].Bindings...) - if err != nil { - logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) - tc.IncFailed() - failer.FailNow(ctx) - } - ctx := testing.IntoContext(ctx, t) - size := len("@chainsaw") - for i, step := range test.Test.Spec.Steps { - name := step.Name - if name == "" { - name = fmt.Sprintf("step-%d", i+1) - } - if size < len(name) { - size = len(name) - } - } - ctx = logging.IntoContext(ctx, logging.NewLogger(t, clock, test.Test.Name, fmt.Sprintf("%-*s", size, "@chainsaw"))) - info := TestInfo{ - Id: i + 1, - ScenarioId: s + 1, - Metadata: test.Test.ObjectMeta, - } - tc = tc.WithBinding(ctx, "test", info) - t.Cleanup(func() { - if t.Skipped() { - tc.IncSkipped() - } else { - if t.Failed() { - tc.IncFailed() - } else { - tc.IncPassed() - } - } - }) - // TODO: move into each test processor - if test.Test.Spec.Concurrent == nil || *test.Test.Spec.Concurrent { - t.Parallel() - } - if test.Test.Spec.Skip != nil && *test.Test.Spec.Skip { - t.SkipNow() - } - if test.Test.Spec.FailFast != nil { - tc = tc.WithFailFast(ctx, *test.Test.Spec.FailFast) - } - if tc.FailFast() && tc.Failed() > 0 { - t.SkipNow() - } - processor := createTestProcessor(clock, nsOptions, test, size) - processor.Run(ctx, nspacer, tc) - }) - } - } -} - -func createTestProcessor(clock clock.PassiveClock, nsOptions v1alpha2.NamespaceOptions, test discovery.Test, size int) TestProcessor { - return NewTestProcessor( - test, - size, - clock, - nsOptions.Template, - nsOptions.Compiler, - ) -} diff --git a/pkg/runner/run.go b/pkg/runner/run.go index 8290ff41a..1238fa509 100644 --- a/pkg/runner/run.go +++ b/pkg/runner/run.go @@ -10,11 +10,9 @@ import ( "github.com/kyverno/chainsaw/pkg/engine" "github.com/kyverno/chainsaw/pkg/engine/clusters" enginecontext "github.com/kyverno/chainsaw/pkg/engine/context" - "github.com/kyverno/chainsaw/pkg/engine/logging" "github.com/kyverno/chainsaw/pkg/model" "github.com/kyverno/chainsaw/pkg/report" "github.com/kyverno/chainsaw/pkg/runner/internal" - "github.com/kyverno/chainsaw/pkg/runner/processors" "github.com/kyverno/chainsaw/pkg/testing" "k8s.io/client-go/rest" "k8s.io/utils/clock" @@ -64,11 +62,8 @@ func run( F: func(t *testing.T) { t.Helper() t.Parallel() - // configure golang context - ctx := testing.IntoContext(ctx, t) - ctx = logging.IntoContext(ctx, logging.NewLogger(t, clock, t.Name(), "@chainsaw")) // run tests - processors.RunTests(ctx, clock, config.Namespace, tc, tests...) + runTests(ctx, t, clock, config.Namespace, tc, tests...) }, }} deps := &internal.TestDeps{} diff --git a/pkg/runner/test.go b/pkg/runner/test.go new file mode 100644 index 000000000..8d9f71c07 --- /dev/null +++ b/pkg/runner/test.go @@ -0,0 +1,202 @@ +package runner + +import ( + "context" + "fmt" + "time" + + petname "github.com/dustinkirkland/golang-petname" + "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" + "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" + "github.com/kyverno/chainsaw/pkg/cleanup/cleaner" + "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/engine" + "github.com/kyverno/chainsaw/pkg/engine/logging" + "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/model" + "github.com/kyverno/chainsaw/pkg/runner/failer" + "github.com/kyverno/chainsaw/pkg/runner/processors" + "github.com/kyverno/chainsaw/pkg/testing" + "github.com/kyverno/pkg/ext/output/color" + "k8s.io/utils/clock" +) + +func runTest( + ctx context.Context, + t testing.TTest, + clock clock.PassiveClock, + nsOptions v1alpha2.NamespaceOptions, + nspacer namespacer.Namespacer, + tc engine.Context, + test discovery.Test, + testId int, + scenarioId int, + bindings ...v1alpha1.Binding, +) { + // configure golang context + ctx = testing.IntoContext(ctx, t) + size := len("@chainsaw") + for i, step := range test.Test.Spec.Steps { + name := step.Name + if name == "" { + name = fmt.Sprintf("step-%d", i+1) + } + if size < len(name) { + size = len(name) + } + } + ctx = logging.IntoContext(ctx, logging.NewLogger(t, clock, test.Test.Name, fmt.Sprintf("%-*s", size, "@chainsaw"))) + // setup summary + t.Cleanup(func() { + if t.Skipped() { + tc.IncSkipped() + } else if t.Failed() { + tc.IncFailed() + } else { + tc.IncPassed() + } + }) + // setup concurrency + if test.Test.Spec.Concurrent == nil || *test.Test.Spec.Concurrent { + t.Parallel() + } + // setup reporting + report := &model.TestReport{ + BasePath: test.BasePath, + Name: test.Test.Name, + Concurrent: test.Test.Spec.Concurrent, + StartTime: time.Now(), + } + stepReport := &model.StepReport{ + Name: "main", + StartTime: time.Now(), + } + t.Cleanup(func() { + report.EndTime = time.Now() + if t.Skipped() { + report.Skipped = true + } + tc.Report.Add(report) + }) + // setup context + tc = tc.WithBinding(ctx, "test", processors.TestInfo{ + Id: testId, + ScenarioId: scenarioId, + Metadata: test.Test.ObjectMeta, + }) + tc, err := engine.WithBindings(ctx, tc, bindings...) + if err != nil { + logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) + tc.IncFailed() + failer.FailNow(ctx) + } + contextData := processors.ContextData{ + BasePath: test.BasePath, + Catch: test.Test.Spec.Catch, + Cluster: test.Test.Spec.Cluster, + Clusters: test.Test.Spec.Clusters, + DelayBeforeCleanup: test.Test.Spec.DelayBeforeCleanup, + DeletionPropagation: test.Test.Spec.DeletionPropagationPolicy, + SkipDelete: test.Test.Spec.SkipDelete, + Templating: test.Test.Spec.Template, + TerminationGrace: test.Test.Spec.ForceTerminationGracePeriod, + Timeouts: test.Test.Spec.Timeouts, + } + tc, err = processors.SetupContext(ctx, tc, contextData) + if err != nil { + logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) + failer.FailNow(ctx) + } + // skip checks + if test.Test.Spec.Skip != nil && *test.Test.Spec.Skip { + t.SkipNow() + } + if tc.FailFast() && tc.Failed() > 0 { + t.SkipNow() + } + // setup cleaner + mainCleaner := cleaner.New(tc.Timeouts().Cleanup.Duration, nil, tc.DeletionPropagation()) + t.Cleanup(func() { + if !mainCleaner.Empty() { + logging.Log(ctx, logging.Cleanup, logging.BeginStatus, color.BoldFgCyan) + defer func() { + logging.Log(ctx, logging.Cleanup, logging.EndStatus, color.BoldFgCyan) + }() + stepReport := &model.StepReport{ + Name: fmt.Sprintf("cleanup (%s)", stepReport.Name), + StartTime: time.Now(), + } + defer func() { + stepReport.EndTime = time.Now() + report.Add(stepReport) + }() + for _, err := range mainCleaner.Run(ctx, stepReport) { + logging.Log(ctx, logging.Cleanup, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) + failer.Fail(ctx) + } + } + }) + // setup namespace + // TODO: should be part of setupContext ? + if test.Test.Spec.Compiler != nil { + tc = tc.WithDefaultCompiler(string(*test.Test.Spec.Compiler)) + } + nsName := test.Test.Spec.Namespace + if nspacer == nil && nsName == "" { + nsName = fmt.Sprintf("chainsaw-%s", petname.Generate(2, "-")) + } + if nsName != "" { + var nsCleaner cleaner.CleanerCollector + if !tc.SkipDelete() { + nsCleaner = mainCleaner + } + // TODO: this may not use the right default compiler if the template is coming from the config + // but the default compiler is specified at the test level + if template := test.Test.Spec.NamespaceTemplate; template != nil && template.Value() != nil { + nsOptions.Template = template + nsOptions.Compiler = test.Test.Spec.NamespaceTemplateCompiler + } + compilers := tc.Compilers() + if nsOptions.Compiler != nil { + compilers = compilers.WithDefaultCompiler(string(*nsOptions.Compiler)) + } + namespaceData := processors.NamespaceData{ + Cleaner: nsCleaner, + Compilers: compilers, + Name: nsName, + Template: nsOptions.Template, + } + nsTc, namespace, err := processors.SetupNamespace(ctx, tc, namespaceData) + if err != nil { + logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) + failer.FailNow(ctx) + } + tc = nsTc + if namespace != nil { + nspacer = namespacer.New(namespace.GetName()) + } + } + if nspacer != nil { + report.Namespace = nspacer.GetNamespace() + } + // setup bindings + tc, err = processors.SetupBindings(ctx, tc, test.Test.Spec.Bindings...) + if err != nil { + logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) + failer.FailNow(ctx) + } + // run steps + for i, step := range test.Test.Spec.Steps { + name := step.Name + if name == "" { + name = fmt.Sprintf("step-%d", i+1) + } + ctx := logging.IntoContext(ctx, logging.NewLogger(t, clock, test.Test.Name, fmt.Sprintf("%-*s", size, name))) + info := processors.StepInfo{ + Id: i + 1, + } + tc := tc.WithBinding(ctx, "step", info) + processor := processors.NewStepProcessor(step, report, test.BasePath) + processor.Run(ctx, nspacer, tc) + } +} diff --git a/pkg/runner/processors/test_test.go b/pkg/runner/test_test.go similarity index 95% rename from pkg/runner/processors/test_test.go rename to pkg/runner/test_test.go index 103d7e6ff..661df143b 100644 --- a/pkg/runner/processors/test_test.go +++ b/pkg/runner/test_test.go @@ -1,4 +1,4 @@ -package processors +package runner import ( "context" @@ -7,6 +7,7 @@ import ( "github.com/kyverno/chainsaw/pkg/apis" "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" + "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" "github.com/kyverno/chainsaw/pkg/client" fake "github.com/kyverno/chainsaw/pkg/client/testing" "github.com/kyverno/chainsaw/pkg/discovery" @@ -15,6 +16,7 @@ import ( fakeNamespacer "github.com/kyverno/chainsaw/pkg/engine/namespacer/testing" "github.com/kyverno/chainsaw/pkg/loaders/config" "github.com/kyverno/chainsaw/pkg/model" + "github.com/kyverno/chainsaw/pkg/runner/mocks" "github.com/kyverno/chainsaw/pkg/testing" "github.com/stretchr/testify/assert" kerror "k8s.io/apimachinery/pkg/api/errors" @@ -280,21 +282,15 @@ func TestTestProcessor_Run(t *testing.T) { }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - registry := registryMock{} + registry := mocks.Registry{} if tc.client != nil { - registry.client = tc.client + registry.Client = tc.client } - processor := NewTestProcessor( - tc.test, - 0, - tc.clock, - config.Spec.Namespace.Template, - nil, - ) nt := &testing.MockT{} ctx := testing.IntoContext(context.Background(), nt) tcontext := enginecontext.MakeContext(apis.NewBindings(), registry) - processor.Run(ctx, tc.namespacer, tcontext) + nsOptions := v1alpha2.NamespaceOptions{Template: config.Spec.Namespace.Template} + runTest(ctx, nt, tc.clock, nsOptions, tc.namespacer, tcontext, tc.test, 0, 0) if tc.expectedFail { assert.True(t, nt.FailedVar, "expected an error but got none") } else { diff --git a/pkg/runner/tests.go b/pkg/runner/tests.go new file mode 100644 index 000000000..6bb6710fd --- /dev/null +++ b/pkg/runner/tests.go @@ -0,0 +1,75 @@ +package runner + +import ( + "context" + + "github.com/kyverno/chainsaw/pkg/apis/v1alpha2" + "github.com/kyverno/chainsaw/pkg/discovery" + "github.com/kyverno/chainsaw/pkg/engine" + "github.com/kyverno/chainsaw/pkg/engine/logging" + "github.com/kyverno/chainsaw/pkg/engine/namespacer" + "github.com/kyverno/chainsaw/pkg/runner/failer" + "github.com/kyverno/chainsaw/pkg/runner/names" + "github.com/kyverno/chainsaw/pkg/runner/processors" + "github.com/kyverno/chainsaw/pkg/testing" + "github.com/kyverno/pkg/ext/output/color" + "k8s.io/utils/clock" +) + +func runTests(ctx context.Context, t testing.TTest, clock clock.PassiveClock, nsOptions v1alpha2.NamespaceOptions, tc engine.Context, tests ...discovery.Test) { + // configure golang context + ctx = testing.IntoContext(ctx, t) + ctx = logging.IntoContext(ctx, logging.NewLogger(t, clock, t.Name(), "@chainsaw")) + // setup cleaner + cleaner := processors.SetupCleanup(ctx, tc) + // setup namespace + var nspacer namespacer.Namespacer + if nsOptions.Name != "" { + compilers := tc.Compilers() + if nsOptions.Compiler != nil { + compilers = compilers.WithDefaultCompiler(string(*nsOptions.Compiler)) + } + namespaceData := processors.NamespaceData{ + Cleaner: cleaner, + Compilers: compilers, + Name: nsOptions.Name, + Template: nsOptions.Template, + } + nsTc, namespace, err := processors.SetupNamespace(ctx, tc, namespaceData) + if err != nil { + logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) + tc.IncFailed() + failer.FailNow(ctx) + } + tc = nsTc + if namespace != nil { + nspacer = namespacer.New(namespace.GetName()) + } + } + // loop through tests + for i := range tests { + test := tests[i] + name, err := names.Test(tc.FullName(), test) + if err != nil { + logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) + tc.IncFailed() + failer.FailNow(ctx) + } else { + testId := i + 1 + if len(test.Test.Spec.Scenarios) == 0 { + t.Run(name, func(t *testing.T) { + t.Helper() + runTest(ctx, t, clock, nsOptions, nspacer, tc, test, testId, 0) + }) + } else { + for s := range test.Test.Spec.Scenarios { + scenarioId := s + 1 + t.Run(name, func(t *testing.T) { + t.Helper() + runTest(ctx, t, clock, nsOptions, nspacer, tc, test, testId, scenarioId, test.Test.Spec.Scenarios[s].Bindings...) + }) + } + } + } + } +} diff --git a/pkg/runner/processors/tests_test.go b/pkg/runner/tests_test.go similarity index 90% rename from pkg/runner/processors/tests_test.go rename to pkg/runner/tests_test.go index c8d4ed0a7..18a26fc69 100644 --- a/pkg/runner/processors/tests_test.go +++ b/pkg/runner/tests_test.go @@ -1,4 +1,4 @@ -package processors +package runner import ( "context" @@ -11,6 +11,7 @@ import ( "github.com/kyverno/chainsaw/pkg/discovery" enginecontext "github.com/kyverno/chainsaw/pkg/engine/context" "github.com/kyverno/chainsaw/pkg/model" + "github.com/kyverno/chainsaw/pkg/runner/mocks" "github.com/kyverno/chainsaw/pkg/testing" "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/api/errors" @@ -39,7 +40,7 @@ func TestTestsProcessor_Run(t *testing.T) { return nil }, }, - clock: nil, + clock: clock.RealClock{}, bindings: apis.NewBindings(), tests: []discovery.Test{}, expectedFail: false, @@ -61,7 +62,7 @@ func TestTestsProcessor_Run(t *testing.T) { return nil }, }, - clock: nil, + clock: clock.RealClock{}, bindings: apis.NewBindings(), tests: []discovery.Test{}, expectedFail: false, @@ -80,7 +81,7 @@ func TestTestsProcessor_Run(t *testing.T) { return nil }, }, - clock: nil, + clock: clock.RealClock{}, bindings: apis.NewBindings(), tests: []discovery.Test{}, expectedFail: true, @@ -99,7 +100,7 @@ func TestTestsProcessor_Run(t *testing.T) { return errors.NewBadRequest("failed to create namespace") }, }, - clock: nil, + clock: clock.RealClock{}, bindings: apis.NewBindings(), tests: []discovery.Test{}, expectedFail: true, @@ -115,7 +116,7 @@ func TestTestsProcessor_Run(t *testing.T) { return nil }, }, - clock: nil, + clock: clock.RealClock{}, bindings: apis.NewBindings(), tests: []discovery.Test{ { @@ -137,7 +138,7 @@ func TestTestsProcessor_Run(t *testing.T) { return nil }, }, - clock: nil, + clock: clock.RealClock{}, bindings: apis.NewBindings(), tests: []discovery.Test{ { @@ -150,14 +151,14 @@ func TestTestsProcessor_Run(t *testing.T) { }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - registry := registryMock{} + registry := mocks.Registry{} if tc.client != nil { - registry.client = tc.client + registry.Client = tc.client } - nt := testing.MockT{} - ctx := testing.IntoContext(context.Background(), &nt) + nt := &testing.MockT{} + ctx := testing.IntoContext(context.Background(), nt) tcontext := enginecontext.MakeContext(apis.NewBindings(), registry) - RunTests(ctx, tc.clock, tc.config.Namespace, tcontext, tc.tests...) + runTests(ctx, nt, tc.clock, tc.config.Namespace, tcontext, tc.tests...) if tc.expectedFail { assert.True(t, nt.FailedVar, "expected an error but got none") } else {