Add StepHttpIpDiscover tests
This commit is contained in:
parent
df38d11270
commit
61bee60ecf
29
builder/qemu/step_http_ip_discover_test.go
Normal file
29
builder/qemu/step_http_ip_discover_test.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package qemu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/hashicorp/packer/common"
|
||||||
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStepHTTPIPDiscover_Run(t *testing.T) {
|
||||||
|
state := new(multistep.BasicStateBag)
|
||||||
|
step := new(stepHTTPIPDiscover)
|
||||||
|
hostIp := "10.0.2.2"
|
||||||
|
previousHttpIp := common.GetHTTPIP()
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
}
|
||||||
|
httpIp := common.GetHTTPIP()
|
||||||
|
if httpIp != hostIp {
|
||||||
|
t.Fatalf("bad: Http ip is %s but was supposed to be %s", httpIp, hostIp)
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SetHTTPIP(previousHttpIp)
|
||||||
|
}
|
37
builder/vmware/common/step_http_ip_discover_test.go
Normal file
37
builder/vmware/common/step_http_ip_discover_test.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"github.com/hashicorp/packer/common"
|
||||||
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStepHTTPIPDiscover_Run(t *testing.T) {
|
||||||
|
state := testState(t)
|
||||||
|
step := new(StepHTTPIPDiscover)
|
||||||
|
driverMock := state.Get("driver").(Driver)
|
||||||
|
hostIp, _ := driverMock.HostIP(state)
|
||||||
|
previousHttpIp := common.GetHTTPIP()
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
}
|
||||||
|
httpIp := common.GetHTTPIP()
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
common.SetHTTPIP(previousHttpIp)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user