github.phpd.cn/hashicorp/packer@v1.3.2/builder/virtualbox/common/step_suppress_messages_test.go (about) 1 package common 2 3 import ( 4 "context" 5 "errors" 6 "testing" 7 8 "github.com/hashicorp/packer/helper/multistep" 9 ) 10 11 func TestStepSuppressMessages_impl(t *testing.T) { 12 var _ multistep.Step = new(StepSuppressMessages) 13 } 14 15 func TestStepSuppressMessages(t *testing.T) { 16 state := testState(t) 17 step := new(StepSuppressMessages) 18 19 driver := state.Get("driver").(*DriverMock) 20 21 // Test the run 22 if action := step.Run(context.Background(), state); action != multistep.ActionContinue { 23 t.Fatalf("bad action: %#v", action) 24 } 25 if _, ok := state.GetOk("error"); ok { 26 t.Fatal("should NOT have error") 27 } 28 29 if !driver.SuppressMessagesCalled { 30 t.Fatal("should call suppressmessages") 31 } 32 } 33 34 func TestStepSuppressMessages_error(t *testing.T) { 35 state := testState(t) 36 step := new(StepSuppressMessages) 37 38 driver := state.Get("driver").(*DriverMock) 39 driver.SuppressMessagesErr = errors.New("foo") 40 41 // Test the run 42 if action := step.Run(context.Background(), state); action != multistep.ActionHalt { 43 t.Fatalf("bad action: %#v", action) 44 } 45 if _, ok := state.GetOk("error"); !ok { 46 t.Fatal("should have error") 47 } 48 49 if !driver.SuppressMessagesCalled { 50 t.Fatal("should call suppressmessages") 51 } 52 }