diff --git a/easyssh/easyssh_test.go b/easyssh/easyssh_test.go index 59fdd5b..4f9ab16 100644 --- a/easyssh/easyssh_test.go +++ b/easyssh/easyssh_test.go @@ -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) + } +}