-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathconfiguration_test.go
54 lines (50 loc) · 1.21 KB
/
configuration_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
package main
import (
"testing"
)
func TestReadOK(t *testing.T) {
correctfiles := []string{
"testdata/config-example.json",
"testdata/config-example.yaml",
}
for _, testFile := range correctfiles {
c := Configuration{}
c.ConfigurationFile = testFile
err := c.Read()
if err != nil {
t.Fatalf("Could not read correct configuration file : %v with error : %v", c.ConfigurationFile, err)
}
}
}
func TestReadError(t *testing.T) {
wrongfiles := []string{
"", // no file passed
"testdata/", // not a regular file
"testdata/config-bad-wrongFormat.json",
"testdata/config-bad-wrongFormat.yaml",
}
for _, testFile := range wrongfiles {
c := Configuration{}
c.ConfigurationFile = testFile
err := c.Read()
if err == nil {
t.Errorf("reading [%v] file should return an error", c.ConfigurationFile)
}
}
}
func TestWriteOK(t *testing.T) {
correctfiles := []string{
"testdata/config-example.json",
"testdata/config-example.yaml",
}
for _, testFile := range correctfiles {
c := Configuration{}
c.ConfigurationFile = testFile
_ = c.Read()
c.Hash = ""
err := c.Write()
if err != nil {
t.Errorf("Could not write configuration to correct file : %v", c.ConfigurationFile)
}
}
}