forked from zach-klippenstein/goadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
78 lines (68 loc) · 1.96 KB
/
server_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
78
package adb
import (
"fmt"
"testing"
"github.com/yosemite-open/go-adb/wire"
"github.com/stretchr/testify/assert"
)
func TestNewServer_ZeroConfig(t *testing.T) {
config := ServerConfig{fs: &filesystem{
LookPath: func(name string) (string, error) {
if name == AdbExecutableName {
return "/bin/adb", nil
}
return "", fmt.Errorf("invalid name: %s", name)
},
IsExecutableFile: func(path string) error {
if path == "/bin/adb" {
return nil
}
return fmt.Errorf("wrong path: %s", path)
},
}}
serverIf, err := newServer(config)
server := serverIf.(*realServer)
assert.NoError(t, err)
assert.IsType(t, tcpDialer{}, server.config.Dialer)
assert.Equal(t, "127.0.0.1", server.config.Host)
assert.Equal(t, AdbPort, server.config.Port)
assert.Equal(t, fmt.Sprintf("127.0.0.1:%d", AdbPort), server.address)
assert.Equal(t, "/bin/adb", server.config.PathToAdb)
}
type MockDialer struct{}
func (d MockDialer) Dial(address string) (*wire.Conn, error) {
return nil, nil
}
func TestNewServer_CustomConfig(t *testing.T) {
config := ServerConfig{
Dialer: MockDialer{},
Host: "foobar",
Port: 1,
PathToAdb: "/bin/adb",
fs: &filesystem{
IsExecutableFile: func(path string) error {
if path == "/bin/adb" {
return nil
}
return fmt.Errorf("wrong path: %s", path)
},
},
}
serverIf, err := newServer(config)
server := serverIf.(*realServer)
assert.NoError(t, err)
assert.IsType(t, MockDialer{}, server.config.Dialer)
assert.Equal(t, "foobar", server.config.Host)
assert.Equal(t, 1, server.config.Port)
assert.Equal(t, fmt.Sprintf("foobar:1"), server.address)
assert.Equal(t, "/bin/adb", server.config.PathToAdb)
}
func TestNewServer_AdbNotFound(t *testing.T) {
config := ServerConfig{fs: &filesystem{
LookPath: func(name string) (string, error) {
return "", fmt.Errorf("executable not found: %s", name)
},
}}
_, err := newServer(config)
assert.EqualError(t, err, "ServerNotAvailable: could not find adb in PATH")
}