forked from YaoApp/gou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime_test.go
74 lines (64 loc) · 1.96 KB
/
runtime_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
package gou
import (
"context"
"fmt"
"path"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRuntimeLoad(t *testing.T) {
err := TestYao.Load(path.Join(TestScriptRoot, "test.js"), "test")
assert.Nil(t, err)
}
func TestRuntimeExec(t *testing.T) {
ctx := context.Background()
err := TestYao.Load(path.Join(TestScriptRoot, "test.js"), "test")
assert.Equal(t, nil, err)
getArgs := TestYao.New("test", "getArgs").
WithGlobal(map[string]interface{}{"foo": "bar"}).
WithSid("1").
WithContext(ctx)
v, err := getArgs.Call("world", 1, 0.618, []interface{}{"foo", "bar"}, map[string]interface{}{"foo": "bar", "int": 1})
assert.Nil(t, err)
fmt.Println(v)
getArgs = TestYao.New("test", "getArgs").
WithGlobal(map[string]interface{}{"foo": "bar"}).
WithSid("1").
WithContext(ctx)
v, err = getArgs.Call("yao", 2, 1.618, []interface{}{"code", "ping"}, map[string]interface{}{"one": "two", "int": 5})
assert.Nil(t, err)
fmt.Println(v)
}
func TestRuntimeExecES6(t *testing.T) {
ctx := context.Background()
err := TestYao.Load(path.Join(TestScriptRoot, "es6.js"), "es6")
assert.Equal(t, nil, err)
now := TestYao.New("es6", "now").
WithGlobal(map[string]interface{}{"foo": "bar"}).
WithSid("1").
WithContext(ctx)
v, err := now.Call("world", 1, 0.618, []interface{}{"foo", "bar"}, map[string]interface{}{"foo": "bar", "int": 1})
assert.Nil(t, err)
fmt.Println(v)
promiseTest := TestYao.New("es6", "promiseTest").
WithGlobal(map[string]interface{}{"foo": "bar"}).
WithSid("1").
WithContext(ctx)
v, err = promiseTest.Call()
assert.Nil(t, err)
fmt.Println(v)
asyncTest := TestYao.New("es6", "asyncTest").
WithGlobal(map[string]interface{}{"foo": "bar"}).
WithSid("1").
WithContext(ctx)
v, err = asyncTest.Call()
assert.Nil(t, err)
fmt.Println(v)
processTest := TestYao.New("es6", "processTest").
WithGlobal(map[string]interface{}{"foo": "bar"}).
WithSid("1").
WithContext(ctx)
v, err = processTest.Call()
assert.Nil(t, err)
fmt.Println(v)
}