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"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2023-06-29 19:55:40 +00:00
|
|
|
"code.icb4dc0.de/buildr/buildr/modules/plugin"
|
|
|
|
|
2023-05-24 20:11:05 +00:00
|
|
|
"golang.org/x/exp/slog"
|
|
|
|
|
|
|
|
"code.icb4dc0.de/buildr/buildr/modules"
|
2023-06-29 19:55:40 +00:00
|
|
|
"github.com/stretchr/testify/mock"
|
2023-05-24 20:11:05 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|