forked from project-flogo/contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_test.go
50 lines (47 loc) · 766 Bytes
/
set_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package json
import (
"encoding/json"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFnSet(t *testing.T) {
input1 := `{
"key1": 123,
"key2": {
"nested": 345.45,
"deepNesting": {
"key3": 678.567575676,
"key4": [
{
"key5": 7987897.96878
}
],
"key5": [1, 2, 3]
}
},
"key3": [1, 2, 3],
"key4": [
[1, 2],
[3, 4],
[3, 4, 5],
[
3,
4,
{
"key8": 7987897.96878
}
]
]
}`
input2 := "newKey"
input3 := "newVal"
obj := make(map[string]interface{})
err := json.Unmarshal([]byte(input1), &obj)
assert.Nil(t, err)
f := &fnSet{}
v, err := f.Eval(obj, input2, input3)
assert.Nil(t, err)
bytes, _ := json.MarshalIndent(v, "", " ")
fmt.Println(string(bytes))
}