MCPcopy Create free account
hub / github.com/appleboy/easyssh-proxy / TestRunCommand

Function TestRunCommand

easyssh_test.go:133–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

131}
132
133func TestRunCommand(t *testing.T) {
134 // wrong key
135 ssh := &MakeConfig{
136 Server: "localhost",
137 User: "drone-scp",
138 Port: "22",
139 KeyPath: "./tests/.ssh/id_rsa.pub",
140 }
141
142 outStr, errStr, isTimeout, err := ssh.Run("whoami", 10)
143 assert.Equal(t, "", outStr)
144 assert.Equal(t, "", errStr)
145 assert.False(t, isTimeout)
146 assert.Error(t, err)
147
148 ssh = &MakeConfig{
149 Server: "localhost",
150 User: "drone-scp",
151 Port: "22",
152 KeyPath: "./tests/.ssh/id_rsa",
153 }
154
155 outStr, errStr, isTimeout, err = ssh.Run("whoami")
156 assert.Equal(t, "drone-scp\n", outStr)
157 assert.Equal(t, "", errStr)
158 assert.True(t, isTimeout)
159 assert.NoError(t, err)
160
161 // error message: not found
162 outStr, errStr, isTimeout, err = ssh.Run("whoami1234")
163 assert.Equal(t, "", outStr)
164 assert.Equal(t, "sh: whoami1234: not found\n", errStr)
165 assert.True(t, isTimeout)
166 // Process exited with status 127
167 assert.Error(t, err)
168
169 // error message: Run Command Timeout
170 outStr, errStr, isTimeout, err = ssh.Run("sleep 2", 1*time.Second)
171 assert.Equal(t, "", outStr)
172 assert.Equal(t, "", errStr)
173 assert.False(t, isTimeout)
174 assert.Error(t, err)
175 assert.Equal(t, "Run Command Timeout: "+context.DeadlineExceeded.Error(), err.Error())
176
177 // test exit code
178 outStr, errStr, isTimeout, err = ssh.Run("exit 1")
179 assert.Equal(t, "", outStr)
180 assert.Equal(t, "", errStr)
181 assert.True(t, isTimeout)
182 // Process exited with status 1
183 assert.Error(t, err)
184}
185
186func TestSCPCommand(t *testing.T) {
187 // wrong key

Callers

nothing calls this directly

Calls 1

RunMethod · 0.95

Tested by

no test coverage detected