-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagent_test.go
144 lines (125 loc) · 2.95 KB
/
agent_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package designer
import (
"context"
sshclient "github.com/v8platform/agent"
"github.com/v8platform/designer/tests"
"github.com/v8platform/runner"
"github.com/stretchr/testify/suite"
"log"
"os"
"testing"
)
type AgentTestSuite struct {
tests.TestSuite
}
func TestAgent(t *testing.T) {
suite.Run(t, new(AgentTestSuite))
}
func (a *AgentTestSuite) TestStartAgent() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
//
////t := a.T()
//
//go func() {
// defer func() error {
// if err := recover(); err != nil {
// return errors.New(fmt.Sprintf("v8 run agent err:%s", err))
// }
// return nil
// }()
//
process, err := runner.Background(ctx, tests.NewFileIB(a.TempIB), AgentModeOptions{
Visible: true,
SSHHostKeyAuto: true,
BaseDir: "./"},
)
//
//}()
if err != nil {
log.Fatal(err)
}
<-process.Ready()
err = waitAgent(ctx, "localhost:1543")
if err != nil {
log.Fatal(err)
}
//t.R().NoError(err, errors.GetErrorContext(err))
//err := ssh.New("localhost").
// WithUser("admin").
// WithPort("1543"). // Default is 22
// RunCommand("\n common shutdown\n", ssh.CommandOptions{
// Stdout: os.Stdout,
// Stderr: os.Stderr,
// Pipein: os.Pipein,
// })
//if err != nil {
// log.Fatal(err)
//}
logger := log.New(os.Stdout, "", log.LstdFlags)
client, err := sshclient.NewAgentClient("", "", "localhost:1543")
if err != nil {
logger.Fatalf("create agent client %v", err)
}
//err = client.CopyDirTo("./", "./src")
//if err != nil {
// logger.Fatalf("copy file %v", err)
//}
//err = client.CopyFileFrom("./src/agent.go", "./tmp/")
//if err != nil {
// logger.Fatalf("copy file %v", err)
//}
//logger.Printf("copy dir")
//err = client.CopyDirFrom("./src", "./tmp/")
//if err != nil {
// logger.Fatalf("copy file %v", err)
//}
//err = client.Disconnect()
//if err != nil {
// logger.Fatal(err)
//}
//
err = client.Connect()
if err != nil {
logger.Fatal(err)
}
//err = client.LoadCfg("./1Cv8.cf")
//if err != nil {
// logger.Fatal(err)
//}
//
//err = client.DumpCfgToFiles("./src", true)
//if err != nil {
// logger.Fatal(err)
//}
err = client.Disconnect()
if err != nil {
logger.Fatal(err)
}
err = client.Shutdown()
if err != nil {
logger.Fatal(err)
}
//session.WriteChannel(sshclient.CONFIG_COMMAND)
//str := session.ReadChannelTiming(10)
//session.WriteChannel("options list")
//str += session.ReadChannelRegExp(1000, re)
////logger.Println(str)
//
//session.WriteChannel("common connect-ib")
////time.Sleep(time.Second * 1)
//session.WriteChannel("common disconnect-ib")
//str += session.ReadChannelRegExp(1000, re)
////logger.Println(str)
////str = session.ReadChannelTiming(10)
////logger.Println(str)
//
//session.WriteChannel("common connect-ib")
//str += session.ReadChannelRegExp(1000, re)
////logger.Println(str)
//
//session.WriteChannel("common shutdown")
//str += session.ReadChannelExpect(1000, "\r\n]")
//logger.Println(str)
//
}