Check source config.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2016-10-20 13:24:23 +08:00
parent 8e1c8e7bd0
commit ab0143209d
2 changed files with 23 additions and 2 deletions
+8 -2
View File
@@ -70,9 +70,15 @@ func trimPath(keys []string) []string {
func (p Plugin) Exec() error {
if len(p.Config.Host) == 0 || len(p.Config.Username) == 0 || (len(p.Config.Password) == 0 && len(p.Config.Key) == 0) {
log.Println("missing ssh config")
log.Println("missing ssh config (Host, Username, Password or Key)")
return errors.New("missing ssh config")
return errors.New("missing ssh config (Host, Username, Password or Key)")
}
if len(p.Config.Source) == 0 {
log.Println("missing source file list config")
return errors.New("missing source file list config")
}
files := trimPath(p.Config.Source)
+15
View File
@@ -27,6 +27,21 @@ func TestMissingSSHConfig(t *testing.T) {
assert.NotNil(t, err)
}
func TestMissingSourceConfig(t *testing.T) {
plugin := Plugin{
Config: Config{
Host: "example.com",
Username: "ubuntu",
Port: "443",
Password: "1234",
},
}
err := plugin.Exec()
assert.NotNil(t, err)
}
func TestTrimElement(t *testing.T) {
var input, result []string