-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsession_test.go
58 lines (50 loc) · 1.17 KB
/
session_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
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a MIT License that can be
// found in the LICENSE file.
package adb_test
import (
"fmt"
"os"
"testing"
adb "github.com/prife/goadb"
"github.com/stretchr/testify/assert"
)
func TestDevice_Session(t *testing.T) {
d := adbclient.Device(adb.AnyDevice())
session, err := d.NewSession()
if err != nil {
t.Fatal(err)
}
defer session.Close()
out, err := session.CombinedOutput("date")
if err != nil {
t.Fatal(err)
}
fmt.Println(string(out))
}
func TestDevice_SessionNonExistedCommand(t *testing.T) {
d := adbclient.Device(adb.AnyDevice())
session, err := d.NewSession()
if err != nil {
t.Fatal(err)
}
defer session.Close()
out, err := session.CombinedOutput("non-existed-cmd")
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "unexpected error code 127")
fmt.Println(string(out))
}
func TestDevice_SessionLogcat(t *testing.T) {
d := adbclient.Device(adb.AnyDevice())
session, err := d.NewSession()
if err != nil {
t.Fatal(err)
}
defer session.Close()
session.Stdout = os.Stdout
session.Stderr = os.Stderr
err = session.Run("logcat")
if err != nil {
t.Fatal(err)
}
}