Skip to content

Commit

Permalink
remove unused const and adding test to the GetExecutorResult
Browse files Browse the repository at this point in the history
  • Loading branch information
fokion committed Oct 23, 2023
1 parent 47c4e90 commit 5cd5e97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions types_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
}
}
Expand Down
20 changes: 20 additions & 0 deletions types_executor_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 0 additions & 1 deletion venom.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var (
const (
LAZY_JSON_EXPANSION_FLAG = "VENOM_NO_JSON_EXPANSION"
FLAG_ENABLED = "ON"
FLAG_DISABLED = "OFF"
)

func OSExit(exitCode int) {
Expand Down

0 comments on commit 5cd5e97

Please sign in to comment.