From 168117de77df8c0f8a31ffccbfabbc5957591bd5 Mon Sep 17 00:00:00 2001 From: Daniel Jaglowski Date: Thu, 29 Jul 2021 10:48:50 -0400 Subject: [PATCH] Add a few tests to ensure that bracketed fieldsa are useable in move operator (#230) --- .../builtin/transformer/move/config_test.go | 9 +++ .../builtin/transformer/move/move_test.go | 63 +++++++++++++++++++ .../MoveBracketedAttributeToResource.yaml | 3 + 3 files changed, 75 insertions(+) create mode 100644 operator/builtin/transformer/move/testdata/MoveBracketedAttributeToResource.yaml diff --git a/operator/builtin/transformer/move/config_test.go b/operator/builtin/transformer/move/config_test.go index 2657df53..df8d75ea 100644 --- a/operator/builtin/transformer/move/config_test.go +++ b/operator/builtin/transformer/move/config_test.go @@ -60,6 +60,15 @@ func TestGoldenConfig(t *testing.T) { return cfg }(), }, + { + Name: "MoveBracketedAttributeToResource", + Expect: func() *MoveOperatorConfig { + cfg := defaultCfg() + cfg.From = entry.NewAttributeField("dotted.field.name") + cfg.To = entry.NewResourceField("new") + return cfg + }(), + }, { Name: "MoveResourceToAttribute", Expect: func() *MoveOperatorConfig { diff --git a/operator/builtin/transformer/move/move_test.go b/operator/builtin/transformer/move/move_test.go index caef8431..0c82eb50 100644 --- a/operator/builtin/transformer/move/move_test.go +++ b/operator/builtin/transformer/move/move_test.go @@ -138,6 +138,69 @@ func TestProcessAndBuild(t *testing.T) { return e }, }, + { + "MoveBracketedAttributeToResource", + false, + func() *MoveOperatorConfig { + cfg := defaultCfg() + cfg.From = entry.NewAttributeField("dotted.field.name") + cfg.To = entry.NewResourceField("new") + return cfg + }(), + func() *entry.Entry { + e := newTestEntry() + e.Attributes = map[string]string{"dotted.field.name": "val"} + return e + }, + func() *entry.Entry { + e := newTestEntry() + e.Resource = map[string]string{"new": "val"} + e.Attributes = map[string]string{} + return e + }, + }, + { + "MoveBracketedAttributeToBracketedResource", + false, + func() *MoveOperatorConfig { + cfg := defaultCfg() + cfg.From = entry.NewAttributeField("dotted.field.name") + cfg.To = entry.NewResourceField("dotted.field.name") + return cfg + }(), + func() *entry.Entry { + e := newTestEntry() + e.Attributes = map[string]string{"dotted.field.name": "val"} + return e + }, + func() *entry.Entry { + e := newTestEntry() + e.Resource = map[string]string{"dotted.field.name": "val"} + e.Attributes = map[string]string{} + return e + }, + }, + { + "MoveAttributeToBracketedResource", + false, + func() *MoveOperatorConfig { + cfg := defaultCfg() + cfg.From = entry.NewAttributeField("new") + cfg.To = entry.NewResourceField("dotted.field.name") + return cfg + }(), + func() *entry.Entry { + e := newTestEntry() + e.Attributes = map[string]string{"new": "val"} + return e + }, + func() *entry.Entry { + e := newTestEntry() + e.Resource = map[string]string{"dotted.field.name": "val"} + e.Attributes = map[string]string{} + return e + }, + }, { "MoveResourceToAttribute", false, diff --git a/operator/builtin/transformer/move/testdata/MoveBracketedAttributeToResource.yaml b/operator/builtin/transformer/move/testdata/MoveBracketedAttributeToResource.yaml new file mode 100644 index 00000000..435c3ddb --- /dev/null +++ b/operator/builtin/transformer/move/testdata/MoveBracketedAttributeToResource.yaml @@ -0,0 +1,3 @@ +type: move +from: $attributes["dotted.field.name"] +to: $resource.new \ No newline at end of file