Fixes #2699: catch invalid communicator types

This commit is contained in:
Mark Peek 2015-10-11 11:20:50 -07:00
parent 44fd528645
commit 2306f4a4e4
2 changed files with 21 additions and 0 deletions

View File

@ -65,6 +65,10 @@ func (c *Config) Prepare(ctx *interpolate.Context) []error {
if es := c.prepareWinRM(ctx); len(es) > 0 {
errs = append(errs, es...)
}
case "none":
break
default:
return []error{fmt.Errorf("Communicator type %s is invalid", c.Type)}
}
return errs

View File

@ -30,6 +30,23 @@ func TestConfig_none(t *testing.T) {
}
}
func TestConfig_badtype(t *testing.T) {
c := &Config{Type: "foo"}
if err := c.Prepare(testContext(t)); len(err) != 1 {
t.Fatalf("bad: %#v", err)
}
}
func TestConfig_winrm(t *testing.T) {
c := &Config{
Type: "winrm",
WinRMUser: "admin",
}
if err := c.Prepare(testContext(t)); len(err) > 0 {
t.Fatalf("bad: %#v", err)
}
}
func testContext(t *testing.T) *interpolate.Context {
return nil
}