-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain_test.go
86 lines (75 loc) · 2.3 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"io/ioutil"
"os"
"testing"
"github.com/m-lab/go/osx"
"github.com/m-lab/go/rtx"
)
func TestMain(t *testing.T) {
// Write files to a temp directory.
dir, err := ioutil.TempDir("", "TestMain")
rtx.Must(err, "Could not create tempdir")
defer os.RemoveAll(dir)
// Make sure that starting up main() does not cause any panics. There's not
// a lot else we can test, but we can at least make sure that it doesn't
// immediately crash.
for _, v := range []struct{ name, val string }{
{"REPS", "1"},
{"TRACE", "true"},
{"OUTPUT", dir},
{"TCPINFO_EVENTSOCKET", dir + "/eventsock.sock"},
{"PROMETHEUSX_LISTEN_ADDRESS", ":0"},
} {
cleanup := osx.MustSetenv(v.name, v.val)
defer cleanup()
}
// REPS=1 should cause main to run once and then exit.
main()
}
func TestMainWithExcludeOptions(t *testing.T) {
// Write files to a temp directory.
dir, err := ioutil.TempDir("", "TestMain")
rtx.Must(err, "Could not create tempdir")
defer os.RemoveAll(dir)
// Make sure that starting up main() does not cause any panics. There's not
// a lot else we can test, but we can at least make sure that it doesn't
// immediately crash.
for _, v := range []struct{ name, val string }{
{"REPS", "1"},
{"TRACE", "true"},
{"OUTPUT", dir},
{"TCPINFO_EVENTSOCKET", dir + "/eventsock.sock"},
{"PROMETHEUSX_LISTEN_ADDRESS", ":0"},
{"EXCLUDE_SRCPORT", "443"},
{"EXCLUDE_DSTIP", "172.25.0.1"},
} {
cleanup := osx.MustSetenv(v.name, v.val)
defer cleanup()
}
// REPS=1 should cause main to run once and then exit.
main()
}
func TestMainWithBadExcludeOptions(t *testing.T) {
// Write files to a temp directory.
dir, err := ioutil.TempDir("", "TestMain")
rtx.Must(err, "Could not create tempdir")
defer os.RemoveAll(dir)
// Make sure that starting up main() does not cause any panics. There's not
// a lot else we can test, but we can at least make sure that it doesn't
// immediately crash.
for _, v := range []struct{ name, val string }{
{"REPS", "1"},
{"TRACE", "true"},
{"OUTPUT", dir},
{"TCPINFO_EVENTSOCKET", dir + "/eventsock.sock"},
{"PROMETHEUSX_LISTEN_ADDRESS", ":0"},
{"EXCLUDE_SRCPORT", "NOT_AN_INT"},
{"EXCLUDE_DSTIP", ";not-an-ip;"},
} {
cleanup := osx.MustSetenv(v.name, v.val)
defer cleanup()
}
// REPS=1 should cause main to run once and then exit.
main()
}