mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-04 10:15:05 +08:00
refactor: show errors if set password and key at the same time (#62)
This commit is contained in:
@@ -161,6 +161,10 @@ func (p *Plugin) Exec() error {
|
||||
return errors.New("missing ssh config (Host, Username)")
|
||||
}
|
||||
|
||||
if len(p.Config.Password) != 0 || len(p.Config.Key) != 0 {
|
||||
return errors.New("can't set password and key at the same time")
|
||||
}
|
||||
|
||||
if len(p.Config.Source) == 0 || len(p.Config.Target) == 0 {
|
||||
return errors.New("missing source or target config")
|
||||
}
|
||||
|
||||
@@ -47,6 +47,23 @@ func TestMissingSourceConfig(t *testing.T) {
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestSetPasswordAndKey(t *testing.T) {
|
||||
plugin := Plugin{
|
||||
Config: Config{
|
||||
Host: []string{"example.com"},
|
||||
Username: "ubuntu",
|
||||
Port: "443",
|
||||
Password: "1234",
|
||||
Key: "test",
|
||||
},
|
||||
}
|
||||
|
||||
err := plugin.Exec()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, "can't set password and key at the same time", err.Error())
|
||||
}
|
||||
|
||||
func TestTrimElement(t *testing.T) {
|
||||
var input, result []string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user