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