-
Notifications
You must be signed in to change notification settings - Fork 20
/
script_integration_test.go
75 lines (55 loc) · 2.02 KB
/
script_integration_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
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
package overflow
import (
"testing"
"github.com/hexops/autogold"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type AwesomeStruct struct {
First struct {
Nested string `json:"nested"`
} `json:"first"`
}
func TestScriptIntegrationNew(t *testing.T) {
o, err := OverflowTesting()
require.NoError(t, err)
t.Parallel()
mapScript := o.ScriptFileNameFN(`pub fun main() : {String: {String: String}} {
return { "first" : { "nested" : "nestedvalue"}}
}`)
t.Run("Get length from pointer", func(t *testing.T) {
mapScript().AssertLengthWithPointer(t, "/first/nested", 11)
})
t.Run("Get length from pointer map", func(t *testing.T) {
mapScript().AssertLengthWithPointer(t, "/first", 23)
})
t.Run("Get value from pointer", func(t *testing.T) {
mapScript().AssertWithPointer(t, "/first/nested", "nestedvalue")
})
t.Run("Get error from pointer", func(t *testing.T) {
mapScript().AssertWithPointerError(t, "/first/nested2", "Object has no key 'nested2'")
})
t.Run("Get value using want", func(t *testing.T) {
mapScript().AssertWithPointerWant(t, "/first/nested", autogold.Want("nested", "nestedvalue"))
})
t.Run("Get value using want map", func(t *testing.T) {
//Note that wants must have a unique name
mapScript().AssertWithPointerWant(t, "/first", autogold.Want("nestedMap", map[string]interface{}{"nested": "nestedvalue"}))
})
t.Run("Marhal result using pointer", func(t *testing.T) {
var result map[string]string
//Note that wants must have a unique name
err := mapScript().MarshalPointerAs("/first", &result)
assert.NoError(t, err)
assert.Equal(t, "nestedvalue", result["nested"])
})
t.Run("Marhal result", func(t *testing.T) {
var result AwesomeStruct
err := mapScript().MarshalAs(&result)
assert.NoError(t, err)
assert.Equal(t, "nestedvalue", result.First.Nested)
})
t.Run("Get assert with want", func(t *testing.T) {
mapScript().AssertWant(t, autogold.Want("assertWant", map[string]interface{}{"first": map[string]interface{}{"nested": "nestedvalue"}}))
})
}