forked from davidtannock/beanstalkd_exporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
61 lines (54 loc) · 1.54 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"reflect"
"testing"
"gopkg.in/alecthomas/kingpin.v2"
)
func TestInitApplication(t *testing.T) {
expectedFlags := []string{
"web.listen-address",
"web.telemetry-path",
"beanstalkd.address",
"beanstalkd.systemMetrics",
"beanstalkd.allTubes",
"beanstalkd.tubes",
"beanstalkd.tubeMetrics",
"log.level",
"log.format",
}
app := kingpin.New("Test", "")
initApplication(app)
for _, flag := range expectedFlags {
actualFlag := app.GetFlag(flag)
if actualFlag == nil {
t.Errorf("expected flag %v, actual nil", flag)
}
}
}
func TestToStringArray(t *testing.T) {
tests := []struct {
input string
expected []string
}{
{input: "", expected: []string{}},
{input: " ", expected: []string{}},
{input: ",", expected: []string{}},
{input: " , ", expected: []string{}},
{input: "abc", expected: []string{"abc"}},
{input: " abc ", expected: []string{"abc"}},
{input: "abc,", expected: []string{"abc"}},
{input: ",abc", expected: []string{"abc"}},
{input: " abc, ", expected: []string{"abc"}},
{input: " , abc , ", expected: []string{"abc"}},
{input: "abc,def", expected: []string{"abc", "def"}},
{input: " abc,def ", expected: []string{"abc", "def"}},
{input: " abc , def , ", expected: []string{"abc", "def"}},
{input: " , , abc , def,ghi ,", expected: []string{"abc", "def", "ghi"}},
}
for _, tt := range tests {
actual := toStringArray(tt.input)
if !reflect.DeepEqual(tt.expected, actual) {
t.Errorf("expected %v for input %q, actual %v", tt.expected, tt.input, actual)
}
}
}