-
Notifications
You must be signed in to change notification settings - Fork 10
/
config_test.go
108 lines (97 loc) · 2.56 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"testing"
)
func TestNewJTIMONConfig(t *testing.T) {
var xerr error
tests := []struct {
name string
error bool
}{
{"tests/data/noerror.json", false}, // no error
{"tests/data/error.jso", true}, // file does not exists
{"tests/data/error.json", true}, // syntax error in JSON file
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, err := NewJTIMONConfig(test.name)
if err != nil && !test.error {
t.Errorf("NewJTIMONConfig failed, got: %v, want: %v", err, xerr)
}
if err == nil && test.error {
t.Errorf("NewJTIMONConfig failed, got: %v, want error", err)
}
})
}
}
func TestNewJTIMONConfigFilelist(t *testing.T) {
var xerr error
tests := []struct {
name string
error bool
}{
{"tests/data/file_list.json", false}, // no error
{"tests/data/file_list.jso", true}, // file does not exists
{"tests/data/file_list_err.json", true}, // syntax error in JSON file
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, err := NewJTIMONConfigFilelist(test.name)
if err != nil && !test.error {
t.Errorf("NewJTIMONConfig failed, got: %v, want: %v", err, xerr)
}
if err == nil && test.error {
t.Errorf("NewJTIMONConfig failed, got: %v, want error", err)
}
})
}
}
func TestValidateConfig(t *testing.T) {
tests := []struct {
name string
error bool
}{
{"tests/data/noerror.json", false}, // no error
{"tests/data/noerror_internal_jtimon.json", false}, // no error
{"tests/data/error.jso", true}, // file does not exists
{"tests/data/error.json", true}, // syntax error in JSON file
}
for _, test := range tests {
t.Run(test.name, func(*testing.T) {
config, err := NewJTIMONConfig(test.name)
if err != nil {
configString, err := ValidateConfig(config)
if err != nil {
t.Errorf("TestValidateConfig failed. Error: %v\nConfig %s\n", err, configString)
}
}
})
}
}
func TestExploreConfig(t *testing.T) {
t.Run("explore-config", func(t *testing.T) {
_, err := ExploreConfig()
if err != nil {
t.Errorf("ExploreConfig failed, Error: %v\n", err)
}
})
}
func TestStringInSlice(t *testing.T) {
tests := []struct {
name string
value bool
}{
{"first", false},
{"two", true},
{"third", false},
}
configfilelist := []string{"one", "two", "three"}
for _, test := range tests {
t.Run(test.name, func(*testing.T) {
ret := StringInSlice(test.name, configfilelist)
if ret != test.value {
t.Errorf("TeststringInSlice failed")
}
})
}
}