From 98066d068e843007b09d5dbdfedd3a94faf97447 Mon Sep 17 00:00:00 2001 From: Fokion Sotiropoulos Date: Mon, 23 Oct 2023 19:08:00 +0100 Subject: [PATCH] remove unused const and adding test to the GetExecutorResult Signed-off-by: Fokion Sotiropoulos --- types_executor.go | 5 +++-- types_executor_test.go | 20 ++++++++++++++++++++ venom.go | 1 - 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 types_executor_test.go diff --git a/types_executor.go b/types_executor.go index 019ca00e..52b71c39 100644 --- a/types_executor.go +++ b/types_executor.go @@ -165,7 +165,7 @@ func GetExecutorResult(r interface{}) map[string]interface{} { panic(err) } jsonUpdates := os.Getenv(LAZY_JSON_EXPANSION_FLAG) - if jsonUpdates == "ON" { + if jsonUpdates == FLAG_ENABLED { for key, value := range d { switch z := value.(type) { case string: @@ -175,7 +175,8 @@ func GetExecutorResult(r interface{}) map[string]interface{} { } if len(m) > 0 { for s, i := range m { - if !strings.Contains(strings.ToUpper(s), "__Type__") && !strings.Contains(strings.ToUpper(s), "__Len__") { + //we are skipping this as whenever we use a value we will do DumpString or Dump which means will generate those values + if !strings.Contains(strings.ToUpper(s), "__TYPE__") && !strings.Contains(strings.ToUpper(s), "__LEN__") { d[s] = i } } diff --git a/types_executor_test.go b/types_executor_test.go new file mode 100644 index 00000000..33faf91b --- /dev/null +++ b/types_executor_test.go @@ -0,0 +1,20 @@ +package venom + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetExecutorResult(t *testing.T) { + payload := map[string]string{} + payload["key"] = "{\"name\":\"test\"}" + os.Setenv(LAZY_JSON_EXPANSION_FLAG, FLAG_ENABLED) + result := GetExecutorResult(payload) + assert.NotNil(t, result) + assert.Equal(t, "Map", result["__type__"]) + assert.Equal(t, int64(1), result["__len__"]) + assert.Equal(t, "test", result["keyjson.name"]) + os.Unsetenv(LAZY_JSON_EXPANSION_FLAG) +} diff --git a/venom.go b/venom.go index 7d75da8a..4dd676d8 100644 --- a/venom.go +++ b/venom.go @@ -30,7 +30,6 @@ var ( const ( LAZY_JSON_EXPANSION_FLAG = "VENOM_NO_JSON_EXPANSION" FLAG_ENABLED = "ON" - FLAG_DISABLED = "OFF" ) func OSExit(exitCode int) {