-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.go
90 lines (72 loc) · 1.59 KB
/
options_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
package qube_test
import (
"os"
"testing"
"time"
"github.com/creack/pty"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/winebarrel/qube"
)
func Test_Options_BeforerApply_IsTTY(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
stdout := os.Stdout
ptmx, _, err := pty.Open()
require.NoError(err)
os.Stdout = ptmx
t.Cleanup(func() {
os.Stdout = stdout
})
options := qube.Options{}
err = options.BeforeApply()
require.NoError(err)
assert.True(options.Color)
}
func Test_Options_BeforerApply_IsNotTTY(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
options := qube.Options{}
err := options.BeforeApply()
require.NoError(err)
assert.False(options.Color)
}
func Test_Options_AfterApply(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
ds := []struct {
DSN string
Driver qube.DBDriver
}{
{
DSN: testDSN_MySQL,
Driver: qube.DBDriverMySQL,
},
{
DSN: testDSN_PostgreSQL,
Driver: qube.DBDriverPostgreSQL,
},
}
for _, d := range ds {
options := qube.Options{
Time: 3 * time.Second,
DBConfig: qube.DBConfig{
DSN: d.DSN,
},
}
err := options.AfterApply()
require.NoError(err)
assert.Equal(qube.JSONDuration(3*time.Second), options.X_Time)
assert.Equal(d.Driver, options.Driver)
}
}
func Test_Options_AfterApply_InvalidDSN(t *testing.T) {
assert := assert.New(t)
options := qube.Options{
DBConfig: qube.DBConfig{
DSN: "**invalid**",
},
}
err := options.AfterApply()
assert.ErrorContains(err, "cannot parse DSN - **invalid**")
}