This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreplay_test.go
80 lines (64 loc) · 2.57 KB
/
replay_test.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main_test
import (
"strings"
"testing"
"github.com/stealthrocket/timecraft/internal/assert"
)
var replay = tests{
"show the replay command help with the short option": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "replay", "-h")
assert.Equal(t, exitCode, 0)
assert.HasPrefix(t, stdout, "Usage:\ttimecraft replay ")
assert.Equal(t, stderr, "")
},
"show the replay command help with the long option": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "replay", "--help")
assert.Equal(t, exitCode, 0)
assert.HasPrefix(t, stdout, "Usage:\ttimecraft replay ")
assert.Equal(t, stderr, "")
},
"standard output is printed during replays": func(t *testing.T) {
stdout, processID, exitCode := timecraft(t, "run", "--", "./testdata/go/urandom.wasm")
assert.Equal(t, exitCode, 0)
replay, stderr, exitCode := timecraft(t, "replay", strings.TrimSpace(processID))
assert.Equal(t, exitCode, 0)
assert.Equal(t, replay, stdout)
assert.Equal(t, stderr, "")
},
"standard output is not printed during quiet replays": func(t *testing.T) {
stdout, processID, exitCode := timecraft(t, "run", "--", "./testdata/go/urandom.wasm")
assert.Equal(t, exitCode, 0)
assert.NotEqual(t, stdout, "")
replay, stderr, exitCode := timecraft(t, "replay", strings.TrimSpace(processID), "-q")
assert.Equal(t, exitCode, 0)
assert.Equal(t, replay, "")
assert.Equal(t, stderr, "")
},
"guest can interact with host via gRPC": func(t *testing.T) {
stdout, processID, exitCode := timecraft(t, "run", "--", "./testdata/go/grpc.wasm")
assert.Equal(t, exitCode, 0)
assert.Equal(t, stdout, "devel\n")
replay, stderr, exitCode := timecraft(t, "replay", strings.TrimSpace(processID))
assert.Equal(t, exitCode, 0)
assert.Equal(t, replay, stdout)
assert.Equal(t, stderr, "")
},
"guest can submit tasks and wait for their completion": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "run", "--", "./testdata/go/task.wasm")
println(stdout)
println(stderr)
assert.Equal(t, exitCode, 0)
processID, _, _ := strings.Cut(stderr, "\n")
replay, _, exitCode := timecraft(t, "replay", strings.TrimSpace(processID))
assert.Equal(t, exitCode, 0)
assert.Equal(t, replay, stdout)
},
"guests can spawn processes": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "run", "--", "./testdata/go/spawn.wasm")
assert.Equal(t, exitCode, 0)
processID, _, _ := strings.Cut(stderr, "\n")
replay, _, exitCode := timecraft(t, "replay", strings.TrimSpace(processID))
assert.Equal(t, exitCode, 0)
assert.Equal(t, replay, stdout)
},
}