-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
73 lines (66 loc) · 1.62 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package goncvoters
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_getConfigurationFileName(t *testing.T) {
tests := []struct {
name string
want string
}{
{"default", "go-ncvoters/config.yaml"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.True(t, strings.HasSuffix(getConfigurationFileName(), tt.want))
})
}
}
func Test_newConfiguration(t *testing.T) {
tests := []struct {
name string
filename string
wantErr bool
}{
{"good", getConfigurationFileName(), false},
{"YAML error", func() string {
filename := filepath.Join(os.TempDir(), "garbled.yaml")
fp, err := os.Create(filename)
assert.Nil(t, err)
defer fp.Close()
fp.WriteString("delete me - this is purposefully garbled")
return filename
}(), true},
{"file not found", "BOGUS", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config := newConfiguration(tt.filename)
if tt.wantErr {
assert.Nil(t, config)
}
_ = config
})
}
}
func Test_configuration_GetColumnNames(t *testing.T) {
filename := "sample_config.yaml"
config := newConfiguration(filename)
names := config.GetColumnNames()
assert.Greater(t, len(names), 0)
}
func Test_configuration_GetSanitizedColumns(t *testing.T) {
filename := "sample_config.yaml"
config := newConfiguration(filename)
names := config.GetSanitizeColumns()
assert.Greater(t, len(names), 0)
}
func Test_configuration_GetTables(t *testing.T) {
filename := "sample_config.yaml"
config := newConfiguration(filename)
names := config.GetTables()
assert.Equal(t, len(names), 0)
}