-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
66 lines (61 loc) · 1.27 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
62
63
64
65
66
package main
import (
"reflect"
"strings"
"testing"
"time"
)
func assertEqual(t *testing.T, is, should interface{}) {
t.Helper()
if should != is {
t.Fatalf("Expected value %v but got %v.", should, is)
}
}
func TestParseFlags(t *testing.T) {
// This test was inspired by Eli Bendersky's 2020 blog post:
// https://eli.thegreenplace.net/2020/testing-flag-parsing-in-go-programs/
tests := []struct {
args []string
conf *config
}{
{
[]string{"-forward-interval", "1", "-key-expiry", "2", "-port", "80"},
&config{
fwdInterval: time.Second,
keyExpiry: time.Second * 2,
port: 80,
prometheusPort: 9090,
},
},
}
for _, test := range tests {
t.Run(
strings.Join(test.args, " "),
func(t *testing.T) {
_, conf, err := parseFlags("tkzr", test.args)
if err != nil {
t.Fatalf("Got unexpected error: %v", err)
}
if !reflect.DeepEqual(conf, test.conf) {
t.Fatalf("Expected conf %+v but got %+v.", test.conf, conf)
}
},
)
}
}
func TestBootstrap(t *testing.T) {
done := make(chan empty)
go func() {
bootstrap(
&config{},
&components{
a: newSimpleAggregator(),
r: newStdinReceiver(),
f: newStdoutForwarder(),
t: newVerbatimTokenizer(),
},
done,
)
}()
close(done)
}