-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwasm_test.go
More file actions
59 lines (54 loc) · 1.39 KB
/
wasm_test.go
File metadata and controls
59 lines (54 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//go:build wazero || wasmtime || wasmer
package main
import (
"bytes"
"context"
"io"
"strings"
"testing"
"time"
)
func testWasmOpenError(t *testing.T, runner Runner) {
conf := SrvConfig{SrvConfigBase{Timeout: time.Duration(1000_000_000)}}
fname := "test.wasm"
stdin := io.NopCloser(bytes.NewBufferString(""))
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
envvar := map[string]string{}
err := runner.Run(conf, fname, envvar, stdin, stdout, stderr, context.Background())
if err == nil {
t.Error("no-error")
}
t.Log("err", err)
}
func testWasmHello(t *testing.T, runner Runner) {
conf := SrvConfig{}
conf.Timeout = time.Duration(1000_000_000)
conf.BaseDir = "examples"
fname := "hello.wasm"
stdin := io.NopCloser(bytes.NewBufferString(""))
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
envvar := map[string]string{}
err := runner.Run(conf, fname, envvar, stdin, stdout, stderr, context.Background())
if err != nil {
t.Errorf("error %s", err)
}
if stderr.String() != "finished(stderr).\n" {
t.Errorf("stderr %s", stderr.String())
}
if !strings.HasPrefix(stdout.String(), "Content-Type:") {
t.Errorf("stdout %s", stdout.String())
}
}
func testWasmAll(t *testing.T, runner Runner) {
t.Parallel()
t.Run("Hello", func(t *testing.T) {
t.Parallel()
testWasmHello(t, runner)
})
t.Run("OpenError", func(t *testing.T) {
t.Parallel()
testWasmOpenError(t, runner)
})
}