-
Notifications
You must be signed in to change notification settings - Fork 553
/
Copy pathregistration_test.go
108 lines (84 loc) · 2.06 KB
/
registration_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package drivers
import (
"testing"
"github.com/volatiletech/sqlboiler/v4/importers"
)
type testRegistrationDriver struct{}
func (t testRegistrationDriver) Assemble(config Config) (*DBInfo, error) {
return &DBInfo{
Tables: nil,
Dialect: Dialect{},
}, nil
}
func (t testRegistrationDriver) Templates() (map[string]string, error) {
return nil, nil
}
func (t testRegistrationDriver) Imports() (importers.Collection, error) {
return importers.Collection{}, nil
}
func TestRegistration(t *testing.T) {
mock := testRegistrationDriver{}
RegisterFromInit("mock1", mock)
if d, ok := registeredDrivers["mock1"]; !ok {
t.Error("driver was not found")
} else if d != mock {
t.Error("got the wrong driver back")
}
}
func TestBinaryRegistration(t *testing.T) {
RegisterBinary("mock2", "/bin/true")
if d, ok := registeredDrivers["mock2"]; !ok {
t.Error("driver was not found")
} else if string(d.(binaryDriver)) != "/bin/true" {
t.Error("got the wrong driver back")
}
}
func TestBinaryFromArgRegistration(t *testing.T) {
RegisterBinaryFromCmdArg("/bin/true/mock5")
if d, ok := registeredDrivers["mock5"]; !ok {
t.Error("driver was not found")
} else if string(d.(binaryDriver)) != "/bin/true/mock5" {
t.Error("got the wrong driver back")
}
}
func TestGetDriver(t *testing.T) {
didYouPanic := false
RegisterBinary("mock4", "/bin/true")
func() {
defer func() {
if r := recover(); r != nil {
didYouPanic = true
}
}()
_ = GetDriver("mock4")
}()
if didYouPanic {
t.Error("expected not to panic when fetching a driver that's known")
}
func() {
defer func() {
if r := recover(); r != nil {
didYouPanic = true
}
}()
_ = GetDriver("notpresentdriver")
}()
if !didYouPanic {
t.Error("expected to recover from a panic")
}
}
func TestReregister(t *testing.T) {
didYouPanic := false
func() {
defer func() {
if r := recover(); r != nil {
didYouPanic = true
}
}()
RegisterBinary("mock3", "/bin/true")
RegisterBinary("mock3", "/bin/true")
}()
if !didYouPanic {
t.Error("expected to recover from a panic")
}
}