Reduces exports and prepares ReleaseModuleInstance for testing (#327)
This removes more exports and adds a toehold test for `ReleaseModuleInstance` so that it can later be completed for both wasm and host modules. Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tetratelabs/wazero/wasm"
|
||||
)
|
||||
|
||||
func TestMemoryInstance_HasLen(t *testing.T) {
|
||||
@@ -448,3 +450,38 @@ func TestMemoryInstance_WriteFloat64Le(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStore_NewHostModule(t *testing.T) {
|
||||
s := newStore()
|
||||
|
||||
// Add the host module
|
||||
_, err := s.NewHostModule("test", map[string]interface{}{"fn": func(wasm.ModuleContext) {}})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ensure it was added to module instances
|
||||
hm := s.moduleInstances["test"]
|
||||
require.NotNil(t, hm)
|
||||
|
||||
// The function was added to the store, prefixed by the owning module name
|
||||
require.Equal(t, 1, len(s.functions))
|
||||
fn := s.functions[0]
|
||||
require.Equal(t, "test.fn", fn.Name)
|
||||
|
||||
// The function was exported in the module
|
||||
require.Equal(t, 1, len(hm.Exports))
|
||||
_, ok := hm.Exports["fn"]
|
||||
require.True(t, ok)
|
||||
|
||||
// Trying to register it again should fail
|
||||
_, err = s.NewHostModule("test", map[string]interface{}{"host_fn": func(wasm.ModuleContext) {}})
|
||||
require.EqualError(t, err, "module test has already been instantiated")
|
||||
}
|
||||
|
||||
func TestHostModule_String(t *testing.T) {
|
||||
s := newStore()
|
||||
|
||||
// Ensure paths that can create the host module can see the name.
|
||||
hm, err := s.NewHostModule("host", map[string]interface{}{"host_fn": func(wasm.ModuleContext) {}})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "HostModule[host]", hm.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user