refactor: show errors if set password and key at the same time (#62)

This commit is contained in:
Bo-Yi Wu
2017-04-21 16:38:43 +08:00
committed by GitHub
parent 88f5a95f3e
commit 049263e847
2 changed files with 21 additions and 0 deletions
+4
View File
@@ -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")
}
+17
View File
@@ -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