-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_test.go
74 lines (66 loc) · 1.68 KB
/
run_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
package main
import (
"os"
"strings"
"syscall"
"testing"
"time"
"github.com/markdingo/autoreverse/database"
"github.com/markdingo/autoreverse/log"
"github.com/markdingo/autoreverse/mock"
"github.com/markdingo/autoreverse/resolver"
)
func TestRun(t *testing.T) {
testCases := []string{
"Local Forward Zone",
"IN/SOA",
"Zone Authority",
"Load Zones Of Authority",
"Load Chaos",
programName,
"Ready",
"Stats: Uptime",
"Stats: Total q=0",
"Stats: A Ptr q=0",
"Stats: AAAA Ptr q=0",
"Stats: A Forward q=0",
"Stats: AAAA Forward q=0",
"Signal",
"log-queries=true",
"log-queries=false",
"PTR-deduce reload",
"LoadAllZones Database Entries",
"initiates shutdown",
"All Listen servers stopped",
}
out := &mock.IOWriter{}
log.SetOut(out)
log.SetLevel(log.MinorLevel)
cfg := newConfig()
cfg.TTLAsSecs = 60
cfg.chaosFlag = true
cfg.reportInterval = time.Second * 3
ar := newAutoReverse(cfg, nil)
ar.generateLocalForward("example.net.")
srv := newServer(cfg, database.NewGetter(), resolver.NewResolver(), nil, "UDP", "[::1]:3053")
ar.servers = append(ar.servers, srv)
ar.startServers()
go ar.Run()
time.Sleep(time.Second * 4) // Give stats report time to trigger
// Send all non-terminating signals and toggle USR2 (--log-queries toggle)
for _, sig := range []os.Signal{syscall.SIGUSR1, syscall.SIGHUP, syscall.SIGUSR2, syscall.SIGUSR2} {
ar.sig <- sig
time.Sleep(time.Millisecond * 100)
}
// Send shutdown and wait for co-routine channel to close
ar.sig <- syscall.SIGTERM
<-ar.Done()
time.Sleep(time.Second)
got := out.String()
for _, s := range testCases {
if !strings.Contains(got, s) {
t.Error("Does not contain", s)
t.Error(got)
}
}
}