This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconfig_test.go
78 lines (75 loc) · 1.95 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
74
75
76
77
78
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoadConfig(t *testing.T) {
t.Run("if the file doesn't exist", func(t *testing.T) {
conf, err := loadConfig("non-existing-file")
assert.Nil(t, conf, "should return nil if the file doesn't exist")
assert.Error(t, err, "should return the error if the file doesn't exist")
})
t.Run("if the json can't be decoded", func(t *testing.T) {
conf, err := loadConfig("config_invalid_test.json")
assert.Nil(t, conf, "should return nil if the json can't be decoded")
assert.Error(t, err, "should return the error if the json can't be decoded")
})
t.Run("default config values", func(t *testing.T) {
conf, err := loadConfig("config_defaults_test.json")
require.NoError(t, err, "should return no error if the config can be loaded")
assert.Equal(t, Config{
Csv: CsvConfig{
Delimiter: ",",
},
Sampling: SamplingConfig{
Mod: 1,
IDColumn: 0,
},
Actions: []ActionConfig{},
}, *conf, "should fill the config with the default values")
})
t.Run("if the config can be loaded", func(t *testing.T) {
gte := 0.0
lt := 100.0
output := "0-100"
conf, err := loadConfig("config_test.json")
require.NoError(t, err, "should return no error if the config can be loaded")
assert.Equal(t, Config{
Csv: CsvConfig{
Delimiter: "|",
},
Sampling: SamplingConfig{
Mod: 77,
IDColumn: 84,
},
Actions: []ActionConfig{
ActionConfig{
Name: "hash",
},
ActionConfig{
Name: "outcode",
},
ActionConfig{
Name: "year",
DateConfig: DateConfig{
Format: "20060102",
},
},
ActionConfig{
Name: "ranges",
RangeConfig: []RangeConfig{
RangeConfig{
Gte: >e,
Lt: <,
Output: &output,
},
},
},
ActionConfig{
Name: "nothing",
},
},
}, *conf, "should return the config properly decoded")
})
}