github.phpd.cn/hashicorp/packer@v1.3.2/builder/oracle/oci/step_image_test.go (about) 1 package oci 2 3 import ( 4 "context" 5 "errors" 6 "testing" 7 8 "github.com/hashicorp/packer/helper/multistep" 9 ) 10 11 func TestStepImage(t *testing.T) { 12 state := testState() 13 state.Put("instance_id", "ocid1...") 14 15 step := new(stepImage) 16 defer step.Cleanup(state) 17 18 if action := step.Run(context.Background(), state); action != multistep.ActionContinue { 19 t.Fatalf("bad action: %#v", action) 20 } 21 22 if _, ok := state.GetOk("image"); !ok { 23 t.Fatalf("should have image") 24 } 25 } 26 27 func TestStepImage_CreateImageErr(t *testing.T) { 28 state := testState() 29 state.Put("instance_id", "ocid1...") 30 31 step := new(stepImage) 32 defer step.Cleanup(state) 33 34 driver := state.Get("driver").(*driverMock) 35 driver.CreateImageErr = errors.New("error") 36 37 if action := step.Run(context.Background(), state); action != multistep.ActionHalt { 38 t.Fatalf("bad action: %#v", action) 39 } 40 41 if _, ok := state.GetOk("error"); !ok { 42 t.Fatalf("should have error") 43 } 44 45 if _, ok := state.GetOk("image"); ok { 46 t.Fatalf("should NOT have image") 47 } 48 } 49 50 func TestStepImage_WaitForImageCreationErr(t *testing.T) { 51 state := testState() 52 state.Put("instance_id", "ocid1...") 53 54 step := new(stepImage) 55 defer step.Cleanup(state) 56 57 driver := state.Get("driver").(*driverMock) 58 driver.WaitForImageCreationErr = errors.New("error") 59 60 if action := step.Run(context.Background(), state); action != multistep.ActionHalt { 61 t.Fatalf("bad action: %#v", action) 62 } 63 64 if _, ok := state.GetOk("error"); !ok { 65 t.Fatalf("should have error") 66 } 67 68 if _, ok := state.GetOk("image"); ok { 69 t.Fatalf("should not have image") 70 } 71 }