2017-05-06 14:37:24 +02:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExecute(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2018-07-15 21:04:17 +02:00
|
|
|
addr := net.TCPAddr{IP: net.ParseIP("fd2f:5119:f2c::127"), Port: 22}
|
2017-05-30 11:17:16 +02:00
|
|
|
|
2017-05-06 14:37:24 +02:00
|
|
|
mgmt := NewManager("~/.ssh/id_rsa")
|
|
|
|
assert.NotNil(mgmt, "no new manager created")
|
|
|
|
|
2018-06-30 01:45:51 +02:00
|
|
|
client, err := mgmt.ConnectTo(addr)
|
2017-05-30 11:17:16 +02:00
|
|
|
assert.NoError(err)
|
2017-05-06 14:37:24 +02:00
|
|
|
|
2017-05-30 11:17:16 +02:00
|
|
|
err = mgmt.ExecuteOn(addr, "uptime")
|
|
|
|
assert.NoError(err)
|
|
|
|
err = mgmt.ExecuteOn(addr, "echo $HOSTNAME")
|
|
|
|
assert.NoError(err)
|
|
|
|
err = mgmt.ExecuteOn(addr, "exit 1")
|
|
|
|
assert.Error(err)
|
2017-05-06 14:37:24 +02:00
|
|
|
|
2018-06-30 01:45:51 +02:00
|
|
|
client.Close()
|
2017-05-06 14:37:24 +02:00
|
|
|
}
|