-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_test.go
56 lines (54 loc) · 1.05 KB
/
config_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
package db
import "testing"
func TestConfig_validate(t *testing.T) {
type fields struct {
Driver string
ConnectionString string
}
init := func(opts ...func(f *fields)) fields {
f := fields{
Driver: "sqlite",
ConnectionString: "file:/path/to/db",
}
for _, opt := range opts {
opt(&f)
}
return f
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "Success Case 1",
fields: init(),
wantErr: false,
},
{
name: "Bad Driver",
fields: init(func(f *fields) {
f.Driver = "bogus"
}),
wantErr: true,
},
{
name: "Empty Connection String",
fields: init(func(f *fields) {
f.ConnectionString = ""
}),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Config{
Driver: tt.fields.Driver,
ConnectionString: tt.fields.ConnectionString,
}
if got := c.validate(); tt.wantErr != (got != nil) {
t.Errorf("ImageConfig.validate() = %v, want error? %v", got, tt.wantErr)
}
})
}
}