wasi-module-sdk-go/examples/hello_world_go/internal/integration/integration_test.go

51 lines
1.2 KiB
Go

//go:generate tinygo build -o hello_world.wasm -scheduler=none -gc=leaking --no-debug -target=wasi ../../main.go
package integration_test
import (
"context"
_ "embed"
"os"
"testing"
"github.com/stretchr/testify/mock"
"golang.org/x/exp/slog"
"code.icb4dc0.de/buildr/buildr/modules"
mm "hello_world/mocks/modules"
)
//go:embed hello_world.wasm
var payload []byte
func TestModule(t *testing.T) {
mod := modules.PluginModule{
PluginCategory: modules.CategoryTask,
PluginType: "hello_world",
PluginPayload: payload,
}.WithSpec(map[string]any{
"Name": "Ted",
})
testCtx := context.Background()
mockCtx := mm.NewMockExecutionContext(t)
mockCtx.EXPECT().Value(mock.Anything).RunAndReturn(func(key any) any {
return testCtx.Value(key)
})
mockCtx.EXPECT().Done().RunAndReturn(func() <-chan struct{} {
return testCtx.Done()
})
mockCtx.EXPECT().WorkingDir().Return(t.TempDir())
mockCtx.EXPECT().OutDir().Return(t.TempDir())
mockCtx.EXPECT().Name().Return("integration_test")
mockCtx.EXPECT().StdOut().Return(os.Stdout)
mockCtx.EXPECT().StdErr().Return(os.Stderr)
mockCtx.EXPECT().Logger().Return(slog.Default())
if err := mod.Execute(mockCtx); err != nil {
t.Fatal(err)
}
}