forked from maxclaus/waitforit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
43 lines (39 loc) · 930 Bytes
/
main_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
package main
import (
"fmt"
"testing"
)
func TestLoadConfig(t *testing.T) {
testCases := []struct {
title string
file string
err string
}{
{
title: "valid config",
file: "./testdata/valid-config.json",
},
{
title: "invalid config",
file: "./testdata/invalid-config.json",
err: "invalid character 'I' looking for beginning of value",
},
{
title: "not existing file",
file: "./testdata/nothing-here.json",
err: "open ./testdata/nothing-here.json: no such file or directory",
},
}
for _, tc := range testCases {
t.Run(tc.title, func(t *testing.T) {
var fc FileConfig
err := loadFileConfig(tc.file, &fc)
errMsg := fmt.Sprintf("%v", err)
if err != nil && tc.err == "" {
t.Errorf(`Expected to NOT fail, got "%v"`, errMsg)
} else if err != nil && tc.err != errMsg {
t.Errorf(`Expected to fail, got "%v" but want "%v"`, errMsg, tc.err)
}
})
}
}