-
Notifications
You must be signed in to change notification settings - Fork 16
/
daemon_test.go
70 lines (61 loc) · 1.84 KB
/
daemon_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
package main
import (
"net"
"net/url"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRunning(t *testing.T) {
mock := setup(t)
defer tearDown(mock)
u, err := url.Parse(mock.server.URL)
assert.Nil(t, err)
h, p, err := net.SplitHostPort(u.Host)
assert.Nil(t, err)
pInt, err := strconv.Atoi(p)
assert.Nil(t, err)
*port = pInt
*bind = h
assert.True(t, running())
}
func TestDaemonizeCmd(t *testing.T) {
p := "/usr/local/bin/notable"
args := []string{p}
name, out := daemonizeCmd(args)
assert.Equal(t, p, name)
assert.Equal(t, []string{"-browser=false", "-daemon=false"}, out)
}
func TestDaemonizeCmdWithBrowser(t *testing.T) {
p := "/usr/local/bin/notable"
args := []string{p, "-browser=true"}
name, out := daemonizeCmd(args)
assert.Equal(t, p, name)
assert.Equal(t, []string{"-browser=false", "-daemon=false"}, out)
}
func TestDaemonizeCmdWithPort(t *testing.T) {
p := "/usr/local/bin/notable"
args := []string{p, "-port=8000"}
name, out := daemonizeCmd(args)
assert.Equal(t, p, name)
assert.Equal(t, []string{"-port=8000", "-browser=false", "-daemon=false"}, out)
}
func TestDaemonizeCmdWantingToDaemonize(t *testing.T) {
p := "/usr/local/bin/notable"
args := []string{p, "-daemon=true"}
name, out := daemonizeCmd(args)
assert.Equal(t, p, name)
assert.Equal(t, []string{"-browser=false", "-daemon=false"}, out)
args = []string{p, "-daemon=true", "-browser=true"}
name, out = daemonizeCmd(args)
assert.Equal(t, p, name)
assert.Equal(t, []string{"-browser=false", "-daemon=false"}, out)
}
func TestDaemonizeCannotRecurse(t *testing.T) {
p := "/usr/local/bin/notable"
// If the args to the running process asked to run in the
// foreground, nothing should even attempt to daemonize it. If
// something accidentally does... panic.
args := []string{p, "-daemon=false"}
assert.Panics(t, func() { daemonizeCmd(args) })
}