mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-04 10:15:05 +08:00
update testing for remove single dest file. (#55)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user