-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcmd_chrome_bridge_test.go
More file actions
101 lines (81 loc) · 2.48 KB
/
cmd_chrome_bridge_test.go
File metadata and controls
101 lines (81 loc) · 2.48 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/StephanSchmidt/human/cmd/cmddaemon"
)
func TestBuildChromeBridgeCmd_Exists(t *testing.T) {
cmd := cmddaemon.BuildChromeBridgeCmd("")
assert.Equal(t, "chrome-bridge", cmd.Use)
assert.NotEmpty(t, cmd.Short)
}
func TestBuildChromeBridgeCmd_ForegroundFlag(t *testing.T) {
cmd := cmddaemon.BuildChromeBridgeCmd("")
fg := cmd.Flags().Lookup("foreground")
require.NotNil(t, fg, "expected --foreground flag to exist")
assert.Equal(t, "false", fg.DefValue, "expected --foreground to default to false")
}
func TestChromeBridge_MissingAddr(t *testing.T) {
t.Setenv("HUMAN_CHROME_ADDR", "")
t.Setenv("HUMAN_DAEMON_TOKEN", "some-token")
cmd := cmddaemon.BuildChromeBridgeCmd("")
var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
err := cmd.Execute()
require.Error(t, err)
assert.Contains(t, err.Error(), "HUMAN_CHROME_ADDR")
}
func TestChromeBridge_MissingToken(t *testing.T) {
t.Setenv("HUMAN_CHROME_ADDR", "localhost:19286")
t.Setenv("HUMAN_DAEMON_TOKEN", "")
cmd := cmddaemon.BuildChromeBridgeCmd("")
var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
err := cmd.Execute()
require.Error(t, err)
assert.Contains(t, err.Error(), "HUMAN_DAEMON_TOKEN")
}
func TestChromeBridge_MissingAddr_Foreground(t *testing.T) {
t.Setenv("HUMAN_CHROME_ADDR", "")
t.Setenv("HUMAN_DAEMON_TOKEN", "some-token")
cmd := cmddaemon.BuildChromeBridgeCmd("")
cmd.SetArgs([]string{"--foreground"})
var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
err := cmd.Execute()
require.Error(t, err)
assert.Contains(t, err.Error(), "HUMAN_CHROME_ADDR")
}
func TestChromeBridge_MissingToken_Foreground(t *testing.T) {
t.Setenv("HUMAN_CHROME_ADDR", "localhost:19286")
t.Setenv("HUMAN_DAEMON_TOKEN", "")
cmd := cmddaemon.BuildChromeBridgeCmd("")
cmd.SetArgs([]string{"--foreground"})
var buf bytes.Buffer
cmd.SetOut(&buf)
cmd.SetErr(&buf)
err := cmd.Execute()
require.Error(t, err)
assert.Contains(t, err.Error(), "HUMAN_DAEMON_TOKEN")
}
func TestChromeBridge_RegisteredInRoot(t *testing.T) {
root := newRootCmd()
found := false
for _, sub := range root.Commands() {
if sub.Name() == "chrome-bridge" {
found = true
break
}
}
assert.True(t, found, "expected chrome-bridge command to be registered")
}
func TestChromeBridgeLogPath(t *testing.T) {
p := cmddaemon.ChromeBridgeLogPath()
assert.Contains(t, p, "chrome-bridge.log")
assert.Contains(t, p, ".human")
}