-
Notifications
You must be signed in to change notification settings - Fork 35
/
main_test.go
77 lines (59 loc) · 1.37 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
package main
import (
"bytes"
"os"
"strings"
"testing"
"time"
"github.com/nanopack/shaman/config"
)
func TestMain(m *testing.M) {
// manually configure
config.LogLevel = "fatal"
discard := &bytes.Buffer{}
shamanTool.SetOutput(discard)
// set args for shaman
args := strings.Split("-O 127.0.0.1:8053 -2 none:// -s", " ")
shamanTool.SetArgs(args)
// run shaman server
go main()
<-time.After(time.Second)
// run tests
rtn := m.Run()
os.Exit(rtn)
}
func TestShowHelp(t *testing.T) {
config.Server = false
shamanTool.SetArgs([]string{""})
shamanTool.Execute()
}
func TestBadConfig(t *testing.T) {
args := strings.Split("-c /tmp/nowaythisexists list", " ")
shamanTool.SetArgs(args)
shamanTool.Execute()
config.ConfigFile = ""
}
func TestShowVersion(t *testing.T) {
args := strings.Split("-v", " ")
shamanTool.SetArgs(args)
shamanTool.Execute()
config.Version = false
}
func TestBadCache(t *testing.T) {
config.L2Connect = "!@#$%^&"
args := strings.Split("-s", " ")
shamanTool.SetArgs(args)
shamanTool.Execute()
config.L2Connect = "none://"
}
func TestBadDNSListen(t *testing.T) {
config.L2Connect = "none://"
config.DnsListen = "127.0.0.1:53"
args := strings.Split("-s", " ")
shamanTool.SetArgs(args)
go shamanTool.Execute()
<-time.After(time.Second)
// port already in use, will fail here
shamanTool.Execute()
config.DnsListen = "127.0.0.1:8053"
}