-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathdata_test.go
More file actions
107 lines (99 loc) · 2.41 KB
/
data_test.go
File metadata and controls
107 lines (99 loc) · 2.41 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package dsunit_test
import (
"github.com/stretchr/testify/assert"
"github.com/viant/endly/service/testing/dsunit"
"github.com/viant/toolbox"
"github.com/viant/toolbox/data"
"log"
"strings"
"testing"
)
var JSON = `
[
{
"Table":"abc",
"Value":[
{
"intBin":{
"$AsInt(1)":"$AsInt(${dsunit.AAAA.SSSSS[0].id})",
"$AsInt(2)":"$id"
}
}
],
"AutoGenerate":{
"id":"uuid.next"
}
}
]
`
var JSON2 = `
[
{
"Table":"xyz",
"Value":[
{
"id": "1",
"800": [
"${featureAggData.featureAgg[0].SessionID}"
]
}
]
}
]
`
func Test_DsUnitUdfGetTableRecords2(t *testing.T) {
var state = data.NewMap()
var records = []interface{}{}
err := toolbox.NewJSONDecoderFactory().Create(strings.NewReader(JSON2)).Decode(&records)
if err != nil {
log.Fatal(err)
}
var collection = data.NewCollection()
collection.Push(map[string]interface{}{
"SessionID": 4,
})
collection.Push(map[string]interface{}{
"SessionID": 2,
})
var featureAggData = data.NewMap()
featureAggData.Put("featureAgg", collection)
state.Put("featureAggData", featureAggData)
state.Put("test", records)
result, err := dsunit.AsTableRecords("test", state)
assert.NotNil(t, result)
tables := toolbox.AsMap(result)
rows := tables["xyz"]
row := toolbox.AsMap(toolbox.AsSlice(rows)[0])
assert.NotNil(t, row)
intBin, ok := row["800"].([]interface{})
if assert.True(t, ok) {
assert.EqualValues(t, 4, intBin[0])
}
}
func Test_DsUnitUdfGetTableRecords(t *testing.T) {
var state = data.NewMap()
collection := data.NewCollection()
var referenceMap = data.NewMap()
referenceMap.Put("id", 1000001)
referenceMap.Put("name", "XZZZEE")
collection.Push(referenceMap)
state.SetValue("dsunit.AAAA.SSSSS", collection)
//state.Put("AsInt", neatly.AsInt)
state.SetValue("uuid.next", 1)
var records = []interface{}{}
err := toolbox.NewJSONDecoderFactory().Create(strings.NewReader(JSON)).Decode(&records)
if err != nil {
log.Fatal(err)
}
state.Put("test", records)
result, err := dsunit.AsTableRecords("test", state)
tables := toolbox.AsMap(result)
rows := tables["abc"]
row := toolbox.AsMap(toolbox.AsSlice(rows)[0])
assert.NotNil(t, row)
intBin, ok := row["intBin"].(map[interface{}]interface{})
if assert.True(t, ok) {
assert.EqualValues(t, 1, intBin[2])
assert.EqualValues(t, 1000001, intBin[1])
}
}