github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/oracle/oci/step_instance_info_test.go (about) 1 package oci 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/mitchellh/multistep" 8 ) 9 10 func TestInstanceInfo(t *testing.T) { 11 state := testState() 12 state.Put("instance_id", "ocid1...") 13 14 step := new(stepInstanceInfo) 15 defer step.Cleanup(state) 16 17 if action := step.Run(state); action != multistep.ActionContinue { 18 t.Fatalf("bad action: %#v", action) 19 } 20 21 instanceIPRaw, ok := state.GetOk("instance_ip") 22 if !ok { 23 t.Fatalf("should have instance_ip") 24 } 25 26 if instanceIPRaw.(string) != "ip" { 27 t.Fatalf("should've got ip ('%s' != 'ip')", instanceIPRaw.(string)) 28 } 29 } 30 31 func TestInstanceInfo_GetInstanceIPErr(t *testing.T) { 32 state := testState() 33 state.Put("instance_id", "ocid1...") 34 35 step := new(stepInstanceInfo) 36 defer step.Cleanup(state) 37 38 driver := state.Get("driver").(*driverMock) 39 driver.GetInstanceIPErr = errors.New("error") 40 41 if action := step.Run(state); action != multistep.ActionHalt { 42 t.Fatalf("bad action: %#v", action) 43 } 44 45 if _, ok := state.GetOk("error"); !ok { 46 t.Fatalf("should have error") 47 } 48 49 if _, ok := state.GetOk("instance_ip"); ok { 50 t.Fatalf("should NOT have instance_ip") 51 } 52 }