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 pathexport_test.go
66 lines (55 loc) · 2.14 KB
/
export_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
package main_test
import (
"os"
"strings"
"testing"
"github.com/stealthrocket/timecraft/internal/assert"
)
var export = tests{
"show the export command help with the short option": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "export", "-h")
assert.Equal(t, exitCode, 0)
assert.HasPrefix(t, stdout, "Usage:\ttimecraft export ")
assert.Equal(t, stderr, "")
},
"show the export command help with the long option": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "export", "--help")
assert.Equal(t, exitCode, 0)
assert.HasPrefix(t, stdout, "Usage:\ttimecraft export ")
assert.Equal(t, stderr, "")
},
"export without a resource type": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "export")
assert.Equal(t, exitCode, 2)
assert.Equal(t, stdout, "")
assert.HasPrefix(t, stderr, "Expected resource type, id, and output file as argument")
},
"export without a resource id": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "export", "profile")
assert.Equal(t, exitCode, 2)
assert.Equal(t, stdout, "")
assert.HasPrefix(t, stderr, "Expected resource type, id, and output file as argument")
},
"export without an output file": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "export", "profile", "74080192e42e")
assert.Equal(t, exitCode, 2)
assert.Equal(t, stdout, "")
assert.HasPrefix(t, stderr, "Expected resource type, id, and output file as argument")
},
"export a module to stdout": func(t *testing.T) {
stdout, processID, exitCode := timecraft(t, "run", "./testdata/go/sleep.wasm", "1ns")
assert.Equal(t, exitCode, 0)
assert.Equal(t, stdout, "sleeping for 1ns\n")
assert.NotEqual(t, processID, "")
moduleID, stderr, exitCode := timecraft(t, "get", "mod", "-q")
assert.Equal(t, exitCode, 0)
assert.Equal(t, stderr, "")
moduleID = strings.TrimSuffix(moduleID, "\n")
moduleData, stderr, exitCode := timecraft(t, "export", "mod", moduleID, "-")
assert.Equal(t, exitCode, 0)
assert.Equal(t, stderr, "")
sleepWasm, err := os.ReadFile("./testdata/go/sleep.wasm")
assert.OK(t, err)
assert.True(t, moduleData == string(sleepWasm))
},
}