-
Notifications
You must be signed in to change notification settings - Fork 2
/
runtime_wazero_test.go
139 lines (110 loc) · 4.21 KB
/
runtime_wazero_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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package wasify
// import (
// "context"
// _ "embed"
// "testing"
// "github.com/stretchr/testify/assert"
// "github.com/tetratelabs/wazero/api"
// "github.com/wasify-io/wasify-go/internal/utils"
// )
// //go:embed testdata/wasm/empty_host_func/main.wasm
// var wasm_emptyHostFunc []byte
// func TestNewModuleInstantaion(t *testing.T) {
// testRuntimeConfig := RuntimeConfig{
// Runtime: RuntimeWazero,
// }
// testModuleConfig := ModuleConfig{
// Namespace: "empty_host_func",
// FSConfig: FSConfig{
// Enabled: true,
// HostDir: "test/_data/",
// GuestDir: "/",
// },
// Wasm: Wasm{
// Binary: wasm_emptyHostFunc,
// },
// HostFunctions: []HostFunction{
// {
// Name: "hostFunc",
// Callback: func(ctx context.Context, m ModuleProxy, params Params) *Results {
// return nil
// },
// Params: []ValueType{},
// Results: []ValueType{},
// },
// },
// }
// hash, err := utils.CalculateHash(wasm_emptyHostFunc)
// assert.NoError(t, err, "Expected no error while calculating hash")
// testModuleConfig.Wasm.Hash = hash
// ctx := context.Background()
// t.Run("successful instantiation", func(t *testing.T) {
// runtime, err := NewRuntime(ctx, &testRuntimeConfig)
// assert.NoError(t, err, "Expected no error while creating runtime")
// assert.NotNil(t, runtime, "Expected a non-nil runtime")
// defer func() {
// err = runtime.Close(ctx)
// assert.NoError(t, err, "Expected no error while closing runtime")
// }()
// module, err := runtime.NewModule(ctx, &testModuleConfig)
// assert.NoError(t, err, "Expected no error while creating module")
// assert.NotNil(t, module, "Expected a non-nil module")
// err = module.Close(ctx)
// assert.Nil(t, err, "Expected no error while closing module")
// })
// t.Run("failure due to invalid runtime", func(t *testing.T) {
// invalidConfig := testRuntimeConfig
// invalidConfig.Runtime = 255
// runtime, err := NewRuntime(ctx, &invalidConfig)
// assert.Error(t, err, "Expected an error due to invalid config")
// assert.Nil(t, runtime, "Expected a nil runtime due to invalid config")
// })
// t.Run("failure due to invalid namespace", func(t *testing.T) {
// runtime, err := NewRuntime(ctx, &testRuntimeConfig)
// assert.NoError(t, err, "Expected no error while creating runtime")
// defer func() {
// err = runtime.Close(ctx)
// assert.NoError(t, err, "Expected no error while closing runtime")
// }()
// invalidtestModuleConfig := testModuleConfig
// invalidtestModuleConfig.Namespace = "_invalid_namespace_"
// module, err := runtime.NewModule(ctx, &invalidtestModuleConfig)
// assert.Error(t, err)
// assert.Nil(t, module)
// })
// t.Run("failure due to invalid hash", func(t *testing.T) {
// runtime, err := NewRuntime(ctx, &testRuntimeConfig)
// assert.NoError(t, err, "Expected no error while creating runtime")
// defer func() {
// err = runtime.Close(ctx)
// assert.NoError(t, err, "Expected no error while closing runtime")
// }()
// invalidtestModuleConfig := testModuleConfig
// invalidtestModuleConfig.Wasm.Hash = "invalid_hash"
// module, err := runtime.NewModule(ctx, &invalidtestModuleConfig)
// assert.Error(t, err)
// assert.Nil(t, module)
// })
// t.Run("failure due to invalid wasm", func(t *testing.T) {
// runtime, err := NewRuntime(ctx, &testRuntimeConfig)
// assert.NoError(t, err, "Expected no error while creating runtime")
// defer func() {
// err = runtime.Close(ctx)
// assert.NoError(t, err, "Expected no error while closing runtime")
// }()
// invalidtestModuleConfig := testModuleConfig
// invalidtestModuleConfig.Wasm.Binary = []byte("invalid wasm data")
// invalidtestModuleConfig.Wasm.Hash = ""
// module, err := runtime.NewModule(ctx, &invalidtestModuleConfig)
// assert.Error(t, err)
// assert.Nil(t, module)
// })
// t.Run("test convertToAPIValueTypes", func(t *testing.T) {
// r := &wazeroRuntime{}
// for vt := ValueTypeBytes; vt <= ValueTypeString; vt++ {
// converted := r.convertToAPIValueTypes([]ValueType{vt})
// assert.Len(t, converted, 1, "Unexpected length of converted types for %v", vt)
// assert.Equal(t, api.ValueTypeI64, converted[0], "Unexpected conversion for %v", vt)
// }
// })
// }