Skip to content

Commit 73cc354

Browse files
committed
Added default sep test
1 parent 86022ae commit 73cc354

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

settingo/settings_test.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import (
88
)
99

1010
type TestConfig struct {
11-
Foobar string `settingo:"help text for foobar"`
12-
FoobarInt int `settingo:"help text for FoobarInt"`
13-
FoobarBool bool `settingo:"help text for FoobarBool"`
14-
FoobarMap map[string][]string `settingo:"help text FoobarMap"`
15-
FoobarSlice []string `settingo:"help text for FoobarSlice"`
16-
FoobarSliceSep []string `settingo:"sep=; help text for FoobarSliceSep"`
17-
FooParse string `settingo:"help text for FooParse"`
11+
Foobar string `settingo:"help text for foobar"`
12+
FoobarInt int `settingo:"help text for FoobarInt"`
13+
FoobarBool bool `settingo:"help text for FoobarBool"`
14+
FoobarMap map[string][]string `settingo:"help text FoobarMap"`
15+
FoobarSlice []string `settingo:"help text for FoobarSlice"`
16+
FoobarSliceSep []string `settingo:"sep=; help text for FoobarSliceSep"`
17+
FoobarSliceEmptySep []string `settingo:"help text for FoobarSliceEmptySep"`
18+
FooParse string `settingo:"help text for FooParse"`
1819
}
1920

2021
func Test_struct_types_default(t *testing.T) {
@@ -33,6 +34,9 @@ func Test_struct_types_default(t *testing.T) {
3334
os.Setenv("FOOBARSLICESEP", "itemA;itemB;itemC")
3435
expectedSliceSep := []string{"itemA", "itemB", "itemC"}
3536

37+
os.Setenv("FOOBARSLICEEMPTYSEP", "valA,valB,valC")
38+
expectedSliceEmptySep := []string{"valA", "valB", "valC"}
39+
3640
os.Setenv("FOOPARSE", "postgres://user:[email protected]:5432/mydb")
3741
expectedFooParse := "database.example.com"
3842

@@ -46,13 +50,14 @@ func Test_struct_types_default(t *testing.T) {
4650
})
4751

4852
config := &TestConfig{
49-
Foobar: expected,
50-
FoobarInt: expectedInt,
51-
FoobarBool: expectedBool,
52-
FoobarMap: expectedMap,
53-
FoobarSlice: expectedSlice,
54-
FoobarSliceSep: expectedSliceSep,
55-
FooParse: expectedFooParse,
53+
Foobar: expected,
54+
FoobarInt: expectedInt,
55+
FoobarBool: expectedBool,
56+
FoobarMap: expectedMap,
57+
FoobarSlice: expectedSlice,
58+
FoobarSliceSep: expectedSliceSep,
59+
FoobarSliceEmptySep: expectedSliceEmptySep,
60+
FooParse: expectedFooParse,
5661
}
5762

5863
SETTINGS.LoadStruct(config)
@@ -81,6 +86,10 @@ func Test_struct_types_default(t *testing.T) {
8186
t.Error(config.FoobarSliceSep, " != ", expectedSliceSep)
8287
}
8388

89+
if !reflect.DeepEqual(config.FoobarSliceEmptySep, expectedSliceEmptySep) {
90+
t.Error(config.FoobarSliceEmptySep, " != ", expectedSliceEmptySep)
91+
}
92+
8493
if config.FooParse != expectedFooParse {
8594
t.Error(config.FooParse, " != ", expectedFooParse)
8695
}

0 commit comments

Comments
 (0)