Test for when the config parameter isn't passed
This commit is contained in:
parent
627a8fe819
commit
6ca02286d4
|
@ -183,6 +183,7 @@ func TestProvisionerPrepare_facterFacts(t *testing.T) {
|
|||
func TestProvisionerPrepare_extraArguments(t *testing.T) {
|
||||
config := testConfig()
|
||||
|
||||
// Test with missing parameter
|
||||
delete(config, "extra_arguments")
|
||||
p := new(Provisioner)
|
||||
err := p.Prepare(config)
|
||||
|
@ -190,7 +191,7 @@ func TestProvisionerPrepare_extraArguments(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Test with malformed fact
|
||||
// Test with malformed value
|
||||
config["extra_arguments"] = "{{}}"
|
||||
p = new(Provisioner)
|
||||
err = p.Prepare(config)
|
||||
|
@ -198,6 +199,7 @@ func TestProvisionerPrepare_extraArguments(t *testing.T) {
|
|||
t.Fatal("should be an error")
|
||||
}
|
||||
|
||||
// Test with valid values
|
||||
config["extra_arguments"] = []string{
|
||||
"arg",
|
||||
}
|
||||
|
@ -222,6 +224,7 @@ func TestProvisionerProvision_extraArguments(t *testing.T) {
|
|||
}
|
||||
config["extra_arguments"] = extraArguments
|
||||
|
||||
// Test with valid values
|
||||
p := new(Provisioner)
|
||||
err := p.Prepare(config)
|
||||
if err != nil {
|
||||
|
@ -238,4 +241,24 @@ func TestProvisionerProvision_extraArguments(t *testing.T) {
|
|||
if !strings.Contains(comm.StartCmd.Command, expectedArgs) {
|
||||
t.Fatalf("Command %q doesn't contain the expected arguments %q", comm.StartCmd.Command, expectedArgs)
|
||||
}
|
||||
|
||||
// Test with missing parameter
|
||||
delete(config, "extra_arguments")
|
||||
|
||||
p = new(Provisioner)
|
||||
err = p.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
err = p.Provision(ui, comm)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Check the expected `extra_arguments` position for an empty value
|
||||
splitCommand := strings.Split(comm.StartCmd.Command, " ")
|
||||
if "" == splitCommand[len(splitCommand)-2] {
|
||||
t.Fatalf("Command %q contains an extra-space which may cause arg parsing issues", comm.StartCmd.Command)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue