Skip to content

Commit

Permalink
ci: fixes broken test setup (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>

Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt authored Aug 19, 2022
1 parent 7611a8a commit 3b882ae
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 22 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
# To simplify setup, we use one Go version, even if it is out of the official version range.
# This version must be <= max version of earliest TinyGo supported and >= min version of latest.
matrix:
go-version: # Note: Go only supports 2 versions: https://go.dev/doc/devel/release#policy
- "1.16" # Minimum Go version of latest TinyGo
- "1.18" # Latest
tinygo-version: # See https://github.com/tinygo-org/tinygo/releases
- "1.16" # Minimum Go version of latest TinyGo albeit EOL.
tinygo-version: # Note: TinyGo only supports latest: https://github.com/tinygo-org/tinygo/releases
- "0.18.0" # First version to use wasi_snapshot_preview1
- "0.25.0" # Latest

steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: ${{ matrix.go-version }}

- name: Install TinyGo
run: | # Installing via curl so commands are similar on OS/x
Expand All @@ -43,7 +44,7 @@ jobs:
run: tinygo build -o example/hello.wasm -scheduler=none --no-debug -target=wasi example/hello.go

- name: Build test wasm
run: cd internal; make build-wasm
run: cd internal/e2e; make

- name: Test
run: go test -v ./...
4 changes: 1 addition & 3 deletions example/hello.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
wapc "github.com/wapc/wapc-guest-tinygo"
)
import "github.com/wapc/wapc-guest-tinygo"

func main() {
wapc.RegisterFunctions(wapc.Functions{
Expand Down
9 changes: 0 additions & 9 deletions internal/Makefile

This file was deleted.

6 changes: 6 additions & 0 deletions internal/e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tinygo_sources := $(wildcard */*.go)
build: $(tinygo_sources)
@echo "Building End-to-End Wasm"
@for f in $^; do \
tinygo build -o $$(echo $$f | sed -e 's/\.go/\.wasm/') -scheduler=none --no-debug -target=wasi $$f; \
done
6 changes: 6 additions & 0 deletions internal/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## waPC Guest Library for TinyGo End-to-End Tests

This is an internal project holding source for various test guest wasm used to
cover corner cases. This has its own [go.mod](go.mod) and [Makefile](Makefile)
as the guest source is compiled with TinyGo, not Go. The `%.wasm` binaries here
are checked in, to ensure end-to-end tests run without any prerequisite setup.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package main

import "github.com/wapc/wapc-guest-tinygo"

func main() {
wapc.ConsoleLog("msg")
wapc.ConsoleLog("msg1")
Expand Down
8 changes: 8 additions & 0 deletions internal/e2e/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/wapc/wapc-guest-tinygo/internal/e2e

// Match min version in go-test.yaml
go 1.16

require github.com/wapc/wapc-guest-tinygo v0.0.0

replace github.com/wapc/wapc-guest-tinygo => ../../
28 changes: 23 additions & 5 deletions internal/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
_ "embed"
"github.com/stretchr/testify/require"
"github.com/tetratelabs/wazero/api"
"log"
"os"
"path"
"testing"

"github.com/tetratelabs/wazero"
Expand All @@ -14,10 +17,25 @@ import (
// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")

// consoleLogWasm was compiled from testdata/__console_log/main.go
//
//go:embed testdata/__console_log/main.wasm
var consoleLogWasm []byte
var guestWasm map[string][]byte

const (
guestWasmConsoleLog = "__console_log"
)

// TestMain ensures we can read the test wasm prior to running e2e tests.
func TestMain(m *testing.M) {
wasms := []string{guestWasmConsoleLog}
guestWasm = make(map[string][]byte, len(wasms))
for _, name := range wasms {
if wasm, err := os.ReadFile(path.Join("e2e", name, "main.wasm")); err != nil {
log.Panicln(err)
} else {
guestWasm[name] = wasm
}
}
os.Exit(m.Run())
}

func Test_EndToEnd(t *testing.T) {
type testCase struct {
Expand All @@ -29,7 +47,7 @@ func Test_EndToEnd(t *testing.T) {
tests := []testCase{
{
name: "ConsoleLog",
guest: consoleLogWasm,
guest: guestWasm[guestWasmConsoleLog],
test: func(t *testing.T, guest api.Module, host *wapcHost) {
// main invokes ConsoleLog
require.Equal(t, []string{"msg", "msg1", "msg"}, host.consoleLogMessages)
Expand Down

0 comments on commit 3b882ae

Please sign in to comment.