From 794280e51994f40524c2b057bac1869615dfb491 Mon Sep 17 00:00:00 2001 From: Evis Drenova <80707987+evisdrenova@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:45:48 -0700 Subject: [PATCH] refactor out null transformer (#491) --- worker/internal/benthos/transformers/null.go | 23 ------------------- .../benthos/transformers/null_test.go | 19 --------------- .../datasync/activities/activities.go | 2 +- .../datasync/activities/activities_test.go | 10 ++++++++ 4 files changed, 11 insertions(+), 43 deletions(-) delete mode 100644 worker/internal/benthos/transformers/null.go delete mode 100644 worker/internal/benthos/transformers/null_test.go diff --git a/worker/internal/benthos/transformers/null.go b/worker/internal/benthos/transformers/null.go deleted file mode 100644 index eaf11c499e..0000000000 --- a/worker/internal/benthos/transformers/null.go +++ /dev/null @@ -1,23 +0,0 @@ -package neosync_transformers - -import ( - "github.com/benthosdev/benthos/v4/public/bloblang" - _ "github.com/benthosdev/benthos/v4/public/components/io" -) - -func init() { - - spec := bloblang.NewPluginSpec() - - // register the function - - err := bloblang.RegisterFunctionV2("transformernull", spec, func(args *bloblang.ParsedParams) (bloblang.Function, error) { - - return func() (any, error) { - return "null", nil - }, nil - }) - if err != nil { - panic(err) - } -} diff --git a/worker/internal/benthos/transformers/null_test.go b/worker/internal/benthos/transformers/null_test.go deleted file mode 100644 index 1ef249899c..0000000000 --- a/worker/internal/benthos/transformers/null_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package neosync_transformers - -import ( - "testing" - - "github.com/benthosdev/benthos/v4/public/bloblang" - "github.com/stretchr/testify/assert" -) - -func TestNullTransformer(t *testing.T) { - mapping := `root = transformernull()` - ex, err := bloblang.Parse(mapping) - assert.NoError(t, err, "failed to parse the null transformer") - - res, err := ex.Query(nil) - assert.NoError(t, err) - - assert.Equal(t, res, "null", "Generated phone number must be the same length as the input phone number") -} diff --git a/worker/pkg/workflows/datasync/activities/activities.go b/worker/pkg/workflows/datasync/activities/activities.go index 5e1c26021b..44b96332e2 100644 --- a/worker/pkg/workflows/datasync/activities/activities.go +++ b/worker/pkg/workflows/datasync/activities/activities.go @@ -1064,7 +1064,7 @@ func computeMutationFunction(col *mgmtv1alpha1.JobMapping) (string, error) { ih := col.Transformer.Config.GetUuidConfig().IncludeHyphen return fmt.Sprintf("uuidtransformer(%t)", ih), nil case "null": - return "transformernull()", nil + return "null", nil case "random_bool": return "randombooltransformer()", nil case "random_string": diff --git a/worker/pkg/workflows/datasync/activities/activities_test.go b/worker/pkg/workflows/datasync/activities/activities_test.go index 0d433f94f0..a6cf2640dd 100644 --- a/worker/pkg/workflows/datasync/activities/activities_test.go +++ b/worker/pkg/workflows/datasync/activities/activities_test.go @@ -296,3 +296,13 @@ func strPtr(val string) *string { func boolPtr(val bool) *bool { return &val } + +func TestNullTransformer(t *testing.T) { + + val, err := computeMutationFunction(&mgmtv1alpha1.JobMapping{Transformer: &mgmtv1alpha1.Transformer{ + Value: "null"}}) + + assert.NoError(t, err) + + assert.Equal(t, val, "null") +}