-
Notifications
You must be signed in to change notification settings - Fork 77
/
init_option_test.go
91 lines (65 loc) · 1.4 KB
/
init_option_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
81
82
83
84
85
86
87
88
89
90
91
package pgs
import (
"bytes"
"math/rand"
"os"
"strconv"
"testing"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDebugMode(t *testing.T) {
t.Parallel()
g := &Generator{}
assert.False(t, g.debug)
DebugMode()(g)
assert.True(t, g.debug)
}
func TestDebugEnv(t *testing.T) {
t.Parallel()
g := &Generator{}
assert.False(t, g.debug)
e := strconv.Itoa(rand.Int())
DebugEnv(e)(g)
assert.False(t, g.debug)
assert.NoError(t, os.Setenv(e, "1"))
DebugEnv(e)(g)
assert.True(t, g.debug)
}
func TestFileSystem(t *testing.T) {
t.Parallel()
p := dummyPersister(InitMockDebugger())
g := &Generator{persister: p}
fs := afero.NewMemMapFs()
FileSystem(fs)(g)
assert.Equal(t, fs, p.fs)
}
func TestProtocInput(t *testing.T) {
t.Parallel()
g := &Generator{}
assert.Nil(t, g.in)
b := &bytes.Buffer{}
ProtocInput(b)(g)
assert.Equal(t, b, g.in)
}
func TestProtocOutput(t *testing.T) {
t.Parallel()
g := &Generator{}
assert.Nil(t, g.out)
b := &bytes.Buffer{}
ProtocOutput(b)(g)
assert.Equal(t, b, g.out)
}
func TestBiDirectional(t *testing.T) {
t.Parallel()
g := &Generator{}
assert.Nil(t, g.workflow)
BiDirectional()(g)
wf := g.workflow
require.IsType(t, &onceWorkflow{}, wf)
once := wf.(*onceWorkflow)
require.IsType(t, &standardWorkflow{}, once.workflow)
std := once.workflow.(*standardWorkflow)
assert.True(t, std.BiDi)
}