test: add easyssh scp and ssh command testing. (#29)

This commit is contained in:
Bo-Yi Wu
2017-02-04 20:50:51 +08:00
committed by GitHub
parent d673dc3a68
commit 0d84586fb1
+37
View File
@@ -1,6 +1,8 @@
package easyssh
import (
"os"
"os/user"
"testing"
"github.com/stretchr/testify/assert"
@@ -20,3 +22,38 @@ func TestGetKeyFile(t *testing.T) {
_, err = getKeyFile("../tests/.ssh/id_rsa")
assert.NoError(t, err)
}
func TestRunCommand(t *testing.T) {
ssh := &MakeConfig{
Server: "localhost",
User: "drone-scp",
Port: "22",
KeyPath: "../tests/.ssh/id_rsa",
}
output, err := ssh.Run("whoami")
assert.Equal(t, "drone-scp\n", output)
assert.NoError(t, err)
}
func TestSCPCommand(t *testing.T) {
ssh := &MakeConfig{
Server: "localhost",
User: "drone-scp",
Port: "22",
KeyPath: "../tests/.ssh/id_rsa",
}
err := ssh.Scp("../tests/a.txt")
assert.NoError(t, err)
u, err := user.Lookup("drone-scp")
if err != nil {
t.Fatalf("Lookup: %v", err)
}
// check file exist
if _, err := os.Stat(u.HomeDir + "/a.txt"); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
}