ssh/client_test.go

53 lines
848 B
Go
Raw Normal View History

2018-11-06 15:37:35 +08:00
package ssh
import (
"fmt"
"testing"
)
func TestNewWithAgent(t *testing.T) {
c, err := NewWithAgent("118.190.117.250", "3009", "root")
if err != nil {
fmt.Println(err)
return
}
defer c.Close()
2019-03-12 17:12:42 +08:00
b, err := c.Output("id")
2018-11-06 15:37:35 +08:00
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(b))
}
func TestNewClient(t *testing.T) {
c, err := NewClient("192.168.5.154", "22", "root", "123456")
if err != nil {
fmt.Println(err)
return
}
defer c.Close()
2019-03-12 17:12:42 +08:00
b, err := c.Output("id")
2018-11-06 15:37:35 +08:00
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(b))
}
func TestNewWithPrivateKey(t *testing.T) {
c, err := NewWithPrivateKey("192.168.5.154", "22", "root", "123456")
if err != nil {
fmt.Println(err)
return
}
defer c.Close()
2019-03-12 17:12:42 +08:00
b, err := c.Output("id")
2018-11-06 15:37:35 +08:00
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(b))
}