freifunkmanager/ssh/run_test.go

30 lines
567 B
Go
Raw Permalink Normal View History

2017-05-06 14:37:24 +02:00
package ssh
import (
"net"
"strconv"
"testing"
2018-07-24 15:07:11 +02:00
"time"
2017-05-06 14:37:24 +02:00
"github.com/stretchr/testify/assert"
)
func TestRun(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}
2018-08-10 13:46:18 +02:00
mgmt := NewManager("~/.ssh/id_rsa", 5*time.Second)
2017-05-06 14:37:24 +02:00
assert.NotNil(mgmt, "no new manager created")
2018-06-30 01:45:51 +02:00
client, err := mgmt.ConnectTo(addr)
assert.NoError(err)
2018-06-30 01:45:51 +02:00
client.Close()
2017-05-06 14:37:24 +02:00
result, err := mgmt.RunOn(addr, "echo 16")
2017-05-06 14:37:24 +02:00
assert.NoError(err)
str := SSHResultToString(result)
resultInt, _ := strconv.Atoi(str)
2017-05-06 14:37:24 +02:00
assert.Equal(16, resultInt)
}