Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madflojo committed Dec 17, 2023
1 parent 6c918ab commit 8914c7d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 95 deletions.
85 changes: 1 addition & 84 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,89 +18,6 @@ jobs:
with:
go-version: '1.21'
- name: Execute Tests
run: make build tests-base
run: make tests
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

redis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: Execute Tests
run: make build tests-redis
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

cassandra:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: Execute Tests
run: make build tests-cassandra
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3


boltdb:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: Build Test WASM Modules
run: make build
- name: Execute Tests
run: make build tests-boltdb
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3


in-memory:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: Execute Tests
run: make build tests-inmemory
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3


mysql:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: Execute Tests
run: make build tests-mysql
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

postgres:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: Execute Tests
run: make build tests-postgres
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build:
$(MAKE) -C testdata/hello-go build

tests: build
go test --race -v -covermode=atomic -coverprofile=coverage.out ./...
1 change: 0 additions & 1 deletion testdata/hello-go/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
build:
## Run TinyGo build via Docker because its easier
docker run -v `pwd`/:/build -w /build tinygo/tinygo:0.25.0 tinygo build -o /build/hello.wasm -target wasi /build/main.go
4 changes: 2 additions & 2 deletions testdata/hello-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

func main() {
// Register the functions that can be called from the host
// multiple functions can be registered at once.
// Register the functions that can be called from the host
// multiple functions can be registered at once.
wapc.RegisterFunctions(wapc.Functions{
"example": Example,
})
Expand Down
4 changes: 2 additions & 2 deletions wasm/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (s *Server) Module(key string) (*Module, error) {
}

// Run will fetch an instance from the module pool and execute it.
func (m *Module) Run(handler string, payload []byte) ([]byte, error) {
func (m *Module) Run(function string, payload []byte) ([]byte, error) {
var r []byte
i, err := m.pool.Get(time.Duration(DefaultPoolTimeout * time.Second))
if err != nil {
Expand All @@ -176,7 +176,7 @@ func (m *Module) Run(handler string, payload []byte) ([]byte, error) {
}
}()

r, err = i.Invoke(m.ctx, handler, payload)
r, err = i.Invoke(m.ctx, function, payload)
if err != nil {
return r, fmt.Errorf("invocation of WASM module failed - %s", err)
}
Expand Down
12 changes: 6 additions & 6 deletions wasm/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestWASMModuleCreation(t *testing.T) {
ModuleConf: ModuleConfig{
Name: "A Module",
PoolSize: 99,
Filepath: "/testdata/logger/tarmac.wasm",
Filepath: "../testdata/hello-go/hello.wasm",
},
})

Expand All @@ -47,7 +47,7 @@ func TestWASMModuleCreation(t *testing.T) {
Pass: false,
ModuleConf: ModuleConfig{
PoolSize: 99,
Filepath: "/testdata/logger/tarmac.wasm",
Filepath: "../testdata/hello-go/hello.wasm",
},
})

Expand All @@ -57,7 +57,7 @@ func TestWASMModuleCreation(t *testing.T) {
Pass: true,
ModuleConf: ModuleConfig{
Name: "A Module",
Filepath: "/testdata/logger/tarmac.wasm",
Filepath: "../testdata/hello-go/hello.wasm",
},
})

Expand All @@ -78,7 +78,7 @@ func TestWASMModuleCreation(t *testing.T) {
ModuleConf: ModuleConfig{
Name: "A Module",
PoolSize: 99,
Filepath: "/doesntexist/testdata/logger/tarmac.wasm",
Filepath: "/doesntexist/testdata/something.wasm",
},
})

Expand Down Expand Up @@ -119,7 +119,7 @@ func TestWASMExecution(t *testing.T) {

err = s.LoadModule(ModuleConfig{
Name: "AModule",
Filepath: "/testdata/logger/tarmac.wasm",
Filepath: "../testdata/hello-go/hello.wasm",
})
if err != nil {
t.Fatalf("Failed to load module - %s", err)
Expand All @@ -131,7 +131,7 @@ func TestWASMExecution(t *testing.T) {
}

go func() {
_, err = m.Run("handler", []byte(`hello`))
_, err = m.Run("example", []byte(`hello`))
if err != nil {
t.Logf("Could not execute the wasm function - %s", err)
}
Expand Down

0 comments on commit 8914c7d

Please sign in to comment.