From 6aa6653378dec0141b5db995e01b2ae16f7d4c5f Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 25 Mar 2017 23:05:13 +0800 Subject: [PATCH] update testing for remove single dest file. (#55) Signed-off-by: Bo-Yi Wu --- plugin.go | 6 +++++- plugin_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/plugin.go b/plugin.go index 9478e81..6e3d878 100644 --- a/plugin.go +++ b/plugin.go @@ -109,12 +109,16 @@ func (p Plugin) log(host string, message ...interface{}) { func (p *Plugin) removeDestFile(ssh *easyssh.MakeConfig) error { p.log(ssh.Server, "remove file", p.DestFile) - _, _, _, err := ssh.Run(fmt.Sprintf("rm -rf %s", p.DestFile), p.Config.CommandTimeout) + _, errStr, _, err := ssh.Run(fmt.Sprintf("rm -rf %s", p.DestFile), p.Config.CommandTimeout) if err != nil { return err } + if errStr != "" { + return errors.New(errStr) + } + return nil } diff --git a/plugin_test.go b/plugin_test.go index f8d97cf..036572c 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -289,3 +289,30 @@ func TestGlobList(t *testing.T) { expects = []string{"tests/b.txt"} assert.Equal(t, expects, globList(paterns)) } + +func TestRemoveDestFile(t *testing.T) { + ssh := &easyssh.MakeConfig{ + Server: "localhost", + User: "drone-scp", + Port: "22", + KeyPath: "tests/.ssh/id_rsa", + // io timeout + Timeout: 1, + } + plugin := Plugin{ + Config: Config{ + CommandTimeout: 60, + }, + DestFile: "/etc/resolv.conf", + } + + // ssh io timeout + err := plugin.removeDestFile(ssh) + assert.Error(t, err) + + ssh.Timeout = 0 + + // permission denied + err = plugin.removeDestFile(ssh) + assert.Error(t, err) +}