forked from microsoft/go-sqlcmd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviper_test.go
More file actions
78 lines (68 loc) · 1.55 KB
/
viper_test.go
File metadata and controls
78 lines (68 loc) · 1.55 KB
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package config
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_configureViper(t *testing.T) {
assert.Panics(t, func() {
_ = configureViper("")
})
}
func Test_configureViperValidExtensions(t *testing.T) {
tests := []string{"config.yaml", "config.yml", "sqlconfig", "/path/to/config.YAML"}
for _, name := range tests {
t.Run(name, func(t *testing.T) {
err := configureViper(name)
assert.NoError(t, err)
})
}
}
func Test_configureViperInvalidExtension(t *testing.T) {
err := configureViper("config.txt")
assert.Error(t, err)
assert.Contains(t, err.Error(), "YAML format")
assert.Contains(t, err.Error(), ".txt")
}
func Test_validateConfigFileExtension(t *testing.T) {
tests := []struct {
name string
file string
wantErr bool
}{
{"yaml extension", "config.yaml", false},
{"yml extension", "config.yml", false},
{"no extension", "sqlconfig", false},
{"uppercase YAML", "config.YAML", false},
{"txt extension", "config.txt", true},
{"json extension", "config.json", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validateConfigFileExtension(tt.file)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}
func Test_Load(t *testing.T) {
SetFileNameForTest(t)
Clean()
Load()
}
func TestNeg_Load(t *testing.T) {
filename = ""
assert.Panics(t, func() {
Load()
})
}
func TestNeg_Save(t *testing.T) {
filename = ""
assert.Panics(t, func() {
Save()
})
}