Skip to content

Commit

Permalink
Removed parseJSON in favor of fromJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
runabol committed Sep 5, 2023
1 parent be396bf commit 1efd857
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 31 deletions.
1 change: 0 additions & 1 deletion eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func EvaluateExpr(ex string, c map[string]any) (any, error) {
"randomInt": randomInt,
"coinflip": coinflip,
"range": range_,
"parseJSON": parseJSON,
}
for k, v := range c {
env[k] = v
Expand Down
4 changes: 2 additions & 2 deletions eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ func TestEvalExpr(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, []any{1, 2, 3}, v)

v, err = eval.EvaluateExpr("{{ parseJSON( inputs.json ) }}", map[string]any{"inputs": map[string]string{
v, err = eval.EvaluateExpr("{{ fromJSON( inputs.json ) }}", map[string]any{"inputs": map[string]string{
"json": "[1,2,3]",
}})
assert.NoError(t, err)
assert.Equal(t, []any{float64(1), float64(2), float64(3)}, v)

v, err = eval.EvaluateExpr("{{ parseJSON( inputs.json ) }}", map[string]any{"inputs": map[string]string{
v, err = eval.EvaluateExpr("{{ fromJSON( inputs.json ) }}", map[string]any{"inputs": map[string]string{
"json": `{"hello":"world"}`,
}})
assert.NoError(t, err)
Expand Down
10 changes: 0 additions & 10 deletions eval/funcs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eval

import (
"encoding/json"
"math/rand"
"reflect"

Expand Down Expand Up @@ -40,12 +39,3 @@ func range_(start, stop int) []int {
}
return result
}

func parseJSON(data string) (any, error) {
var object any
err := json.Unmarshal([]byte(data), &object)
if err != nil {
return nil, err
}
return object, nil
}
14 changes: 0 additions & 14 deletions eval/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ func TestRange(t *testing.T) {
assert.Equal(t, []int{}, result)
}

func Test_parseJSON(t *testing.T) {
result, err := parseJSON(`{"hello":"world"}`)
assert.NoError(t, err)
assert.Equal(t, map[string]any{"hello": "world"}, result)

result, err = parseJSON(`{"somenumber":5}`)
assert.NoError(t, err)
assert.Equal(t, map[string]any{"somenumber": float64(5)}, result)

result, err = parseJSON(`[{"hello":"world"}]`)
assert.NoError(t, err)
assert.Equal(t, []interface{}{map[string]interface{}{"hello": "world"}}, result)
}

func TestRandomInt(t *testing.T) {
for i := 0; i < 100; i++ {
result, err := randomInt(5)
Expand Down
2 changes: 1 addition & 1 deletion examples/split_and_stitch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ tasks:
- name: transcode the chunks in parallel
each:
list: "{{ parseJSON(tasks.chunks) }}"
list: "{{ fromJSON(tasks.chunks) }}"
task:
name: encode the chunk
retry:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/runabol/tork
go 1.19

require (
github.com/antonmedv/expr v1.13.0
github.com/antonmedv/expr v1.15.0
github.com/docker/docker v23.0.6+incompatible
github.com/docker/go-units v0.5.0
github.com/fatih/color v1.15.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/antonmedv/expr v1.13.0 h1:8YrTtlCzlOtXw+hpeCLDLL2uo0C0k6jmYpYTGws5c5w=
github.com/antonmedv/expr v1.13.0/go.mod h1:FPC8iWArxls7axbVLsW+kpg1mz29A1b2M6jt+hZfDkU=
github.com/antonmedv/expr v1.15.0 h1:sBHNMx1i+b1lZfkBFGhicvSLW6RLnca3R0B7jWrk8iM=
github.com/antonmedv/expr v1.15.0/go.mod h1:0E/6TxnOlRNp81GMzX9QfDPAmHo2Phg00y4JUv1ihsE=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down

0 comments on commit 1efd857

Please sign in to comment.