@@ -3,6 +3,8 @@ package main
33import (
44 "context"
55 "io/ioutil"
6+ "log"
7+ "os"
68 "testing"
79 "time"
810
@@ -21,13 +23,15 @@ func TestMetrics(t *testing.T) {
2123func TestMain (t * testing.T ) {
2224 dir , err := ioutil .TempDir ("" , "TestMain" )
2325 rtx .Must (err , "Could not create temp dir" )
26+ defer os .RemoveAll (dir )
2427
2528 // Verify that main doesn't crash, and that it does exit when the context is canceled.
2629 // TODO: verify more in this test.
2730 * prometheusx .ListenAddress = ":0"
2831 * scamperCtrlSocket = dir + "/scamper.sock"
2932 * waitTime = time .Nanosecond // Run through the loop a few times.
3033 * outputPath = dir
34+ * poll = true
3135 tracerType .Value = "scamper"
3236 ctx , cancel = context .WithCancel (context .Background ())
3337 go func () {
@@ -40,13 +44,15 @@ func TestMain(t *testing.T) {
4044func TestMainWithConnectionListener (t * testing.T ) {
4145 dir , err := ioutil .TempDir ("" , "TestMainWithConnectionListener" )
4246 rtx .Must (err , "Could not create temp dir" )
47+ defer os .RemoveAll (dir )
4348 srv := eventsocket .New (dir + "/events.sock" )
4449 rtx .Must (srv .Listen (), "Could not start the empty server" )
4550
4651 * prometheusx .ListenAddress = ":0"
4752 * scamperCtrlSocket = dir + "/scamper.sock"
4853 * eventsocket .Filename = dir + "/events.sock"
4954 * outputPath = dir
55+ * poll = false
5056 tracerType .Value = "paris-traceroute"
5157
5258 ctx , cancel = context .WithCancel (context .Background ())
@@ -57,3 +63,25 @@ func TestMainWithConnectionListener(t *testing.T) {
5763 }()
5864 main ()
5965}
66+
67+ func TestMainWithBadArgs (t * testing.T ) {
68+ tracerType .Value = "paris-traceroute"
69+ * eventsocket .Filename = ""
70+ * outputPath = "/tmp/"
71+ * poll = false
72+
73+ logFatal = func (_ ... interface {}) {
74+ panic ("testpanic" )
75+ }
76+ defer func () {
77+ logFatal = log .Fatal
78+ }()
79+ defer func () {
80+ r := recover ()
81+ if r != "testpanic" {
82+ t .Error ("Should have had a panic called testpanic, not" , r )
83+ }
84+ }()
85+
86+ main ()
87+ }
0 commit comments