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

53 lines
1.2 KiB
Go
Raw Normal View History

2023-05-24 20:11:05 +00:00
//go:generate tinygo build -o hello_world.wasm -scheduler=none -gc=leaking --no-debug -target=wasi ../../main.go
package integration_test
import (
"context"
_ "embed"
2023-08-15 20:10:30 +00:00
"log/slog"
2023-05-24 20:11:05 +00:00
"os"
"testing"
2023-08-15 19:46:02 +00:00
"github.com/stretchr/testify/mock"
2023-05-24 20:11:05 +00:00
"code.icb4dc0.de/buildr/buildr/modules"
mm "hello_world/mocks/modules"
)
//go:embed hello_world.wasm
var payload []byte
func TestModule(t *testing.T) {
2023-06-29 19:55:40 +00:00
mod := plugin.Module{
2023-05-24 20:11:05 +00:00
PluginCategory: modules.CategoryTask,
PluginType: "hello_world",
2023-06-29 19:55:40 +00:00
PluginPayload: plugin.MemoryPayload(payload),
2023-05-24 20:11:05 +00:00
}.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()
})
2023-06-29 19:55:40 +00:00
mockCtx.EXPECT().BinariesDir().Return(t.TempDir())
2023-05-24 20:11:05 +00:00
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)
2023-06-29 19:55:40 +00:00
mockCtx.EXPECT().Logger().Return(slog.Default()).Maybe()
2023-05-24 20:11:05 +00:00
if err := mod.Execute(mockCtx); err != nil {
t.Fatal(err)
}
}