forked from zach-klippenstein/goadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_client_test.go
61 lines (48 loc) · 1.48 KB
/
sync_client_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
// TODO(z): Implement tests for sync_client functions.
package adb
import (
"bytes"
"os"
"testing"
"time"
"github.com/yosemite-open/go-adb/internal/errors"
"github.com/yosemite-open/go-adb/wire"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var someTime = time.Date(2015, 5, 3, 8, 8, 8, 0, time.UTC)
func TestStatValid(t *testing.T) {
var buf bytes.Buffer
conn := &wire.SyncConn{wire.NewSyncScanner(&buf), wire.NewSyncSender(&buf)}
var mode os.FileMode = 0777
conn.SendOctetString("STAT")
conn.SendFileMode(mode)
conn.SendInt32(4)
conn.SendTime(someTime)
entry, err := stat(conn, "/thing")
assert.NoError(t, err)
require.NotNil(t, entry)
assert.Equal(t, mode, entry.Mode, "expected os.FileMode %s, got %s", mode, entry.Mode)
assert.Equal(t, int32(4), entry.Size)
assert.Equal(t, someTime, entry.ModifiedAt)
assert.Equal(t, "", entry.Name)
}
func TestStatBadResponse(t *testing.T) {
var buf bytes.Buffer
conn := &wire.SyncConn{wire.NewSyncScanner(&buf), wire.NewSyncSender(&buf)}
conn.SendOctetString("SPAT")
entry, err := stat(conn, "/")
assert.Nil(t, entry)
assert.Error(t, err)
}
func TestStatNoExist(t *testing.T) {
var buf bytes.Buffer
conn := &wire.SyncConn{wire.NewSyncScanner(&buf), wire.NewSyncSender(&buf)}
conn.SendOctetString("STAT")
conn.SendFileMode(0)
conn.SendInt32(0)
conn.SendTime(time.Unix(0, 0).UTC())
entry, err := stat(conn, "/")
assert.Nil(t, entry)
assert.Equal(t, errors.FileNoExistError, err.(*errors.Err).Code)
}