mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-04 18:23:59 +08:00
test: add easyssh scp and ssh command testing. (#29)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user