-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathcomponent_linker_feat_component_model_test.go
More file actions
84 lines (75 loc) · 1.93 KB
/
component_linker_feat_component_model_test.go
File metadata and controls
84 lines (75 loc) · 1.93 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
package wasmtime
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestComponentInstantiate(t *testing.T) {
cases := []struct {
name string
wat string
}{
{
"hello_component",
`(component
(core module $m (func (export "hello")))
(core instance $i (instantiate $m))
(func (export "hello") (canon lift (core func $i "hello"))))`,
},
{
"empty_component",
`(component)`,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
engine := newComponentEngine()
store := NewStore(engine)
component := newComponent(t, engine, tc.wat)
defer component.Close()
linker := NewComponentLinker(engine)
defer linker.Close()
instance, err := linker.Instantiate(store, component)
require.NoError(t, err)
require.NotNil(t, instance)
})
}
}
func TestComponentDefineUnknownImportsAsTraps(t *testing.T) {
cases := []struct {
name string
wat string
}{
{
"single_missing_instance",
`(component
(import "host:missing/api" (instance
(export "f" (func)))))`,
},
{
"two_missing_instances",
`(component
(import "host:a/api" (instance
(export "f" (func))))
(import "host:b/api" (instance
(export "g" (func)))))`,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
engine := newComponentEngine()
store := NewStore(engine)
component := newComponent(t, engine, tc.wat)
defer component.Close()
linker := NewComponentLinker(engine)
defer linker.Close()
// Without trap definitions the missing imports cause instantiation to fail.
_, err := linker.Instantiate(store, component)
require.Error(t, err, "expected missing import to fail instantiation")
// After defining unknown imports as traps the instantiation succeeds.
require.NoError(t, linker.DefineUnknownImportsAsTraps(component))
instance, err := linker.Instantiate(store, component)
require.NoError(t, err)
require.NotNil(t, instance)
})
}
}