Skip to content

Commit

Permalink
refactor: remove processors package (#2207)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Dec 9, 2024
1 parent 05ef5b1 commit 3977046
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 301 deletions.
94 changes: 47 additions & 47 deletions pkg/runner/processors/context.go → pkg/runner/context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processors
package runner

import (
"context"
Expand All @@ -16,55 +16,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 enginecontext.TestContext, data ContextData) (enginecontext.TestContext, error) {
if len(data.Catch) > 0 {
tc = tc.WithCatch(ctx, data.Catch...)
func setupContext(ctx context.Context, tc enginecontext.TestContext, data contextData) (enginecontext.TestContext, 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 = enginecontext.WithClusters(ctx, tc, data.BasePath, data.Clusters)
if data.Cluster != nil {
if _tc, err := enginecontext.WithCurrentCluster(ctx, tc, *data.Cluster); err != nil {
tc = enginecontext.WithClusters(ctx, tc, data.basePath, data.clusters)
if data.cluster != nil {
if _tc, err := enginecontext.WithCurrentCluster(ctx, tc, *data.cluster); err != nil {
return tc, err
} else {
tc = _tc
Expand All @@ -73,9 +73,9 @@ func SetupContext(ctx context.Context, tc enginecontext.TestContext, data Contex
return tc, nil
}

func SetupNamespace(ctx context.Context, tc enginecontext.TestContext, data NamespaceData) (enginecontext.TestContext, *corev1.Namespace, error) {
func setupNamespace(ctx context.Context, tc enginecontext.TestContext, data namespaceData) (enginecontext.TestContext, *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
Expand All @@ -85,8 +85,8 @@ func SetupNamespace(ctx context.Context, tc enginecontext.TestContext, data Name
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
Expand All @@ -97,7 +97,7 @@ func SetupNamespace(ctx context.Context, tc enginecontext.TestContext, data Name
return tc, ns, nil
}

func SetupBindings(ctx context.Context, tc enginecontext.TestContext, bindings ...v1alpha1.Binding) (enginecontext.TestContext, error) {
func setupBindings(ctx context.Context, tc enginecontext.TestContext, bindings ...v1alpha1.Binding) (enginecontext.TestContext, error) {
if _tc, err := enginecontext.WithBindings(ctx, tc, bindings...); err != nil {
return tc, err
} else {
Expand All @@ -106,7 +106,7 @@ func SetupBindings(ctx context.Context, tc enginecontext.TestContext, bindings .
return tc, nil
}

func SetupCleanup(ctx context.Context, t testing.TTest, onFailure func(), tc enginecontext.TestContext) cleaner.CleanerCollector {
func setupCleanup(ctx context.Context, t testing.TTest, onFailure func(), tc enginecontext.TestContext) cleaner.CleanerCollector {
if tc.SkipDelete() {
return nil
}
Expand All @@ -127,10 +127,10 @@ func SetupCleanup(ctx context.Context, t testing.TTest, onFailure func(), tc eng
return cleaner
}

func setupContextAndBindings(ctx context.Context, tc enginecontext.TestContext, data ContextData, bindings ...v1alpha1.Binding) (enginecontext.TestContext, error) {
if tc, err := SetupContext(ctx, tc, data); err != nil {
func setupContextAndBindings(ctx context.Context, tc enginecontext.TestContext, data contextData, bindings ...v1alpha1.Binding) (enginecontext.TestContext, error) {
if tc, err := setupContext(ctx, tc, data); err != nil {
return tc, err
} else {
return SetupBindings(ctx, tc, bindings...)
return setupBindings(ctx, tc, bindings...)
}
}
2 changes: 1 addition & 1 deletion pkg/runner/processors/info.go → pkg/runner/info.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processors
package runner

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processors
package runner

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processors
package runner

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processors
package runner

import (
"context"
Expand Down
Loading

0 comments on commit 3977046

Please sign in to comment.