2020-01-28 04:22:10 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2020-02-14 11:42:29 -05:00
|
|
|
"testing"
|
|
|
|
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2020-01-28 04:22:10 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepHTTPIPDiscover_Run(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepHTTPIPDiscover)
|
|
|
|
driverMock := state.Get("driver").(Driver)
|
|
|
|
hostIp, _ := driverMock.HostIP(state)
|
|
|
|
|
|
|
|
// Test the run
|
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
2020-05-19 05:49:48 -04:00
|
|
|
httpIp := state.Get("http_ip").(string)
|
2020-01-28 04:22:10 -05:00
|
|
|
if httpIp != hostIp {
|
|
|
|
t.Fatalf("bad: Http ip is %s but was supposed to be %s", httpIp, hostIp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Halt step when fails to get ip
|
|
|
|
state.Put("driver", &DriverMock{HostIPErr: errors.New("error")})
|
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionHalt {
|
|
|
|
t.Fatalf("bad action: step was supposed to fail %#v", action)
|
|
|
|
}
|
|
|
|
}
|