github.phpd.cn/hashicorp/packer@v1.3.2/builder/azure/arm/step_test.go (about) 1 package arm 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/packer/builder/azure/common/constants" 8 "github.com/hashicorp/packer/helper/multistep" 9 ) 10 11 func TestProcessStepResultShouldContinueForNonErrors(t *testing.T) { 12 stateBag := new(multistep.BasicStateBag) 13 14 code := processStepResult(nil, func(error) { t.Fatal("Should not be called!") }, stateBag) 15 if _, ok := stateBag.GetOk(constants.Error); ok { 16 t.Errorf("Error was nil, but was still in the state bag.") 17 } 18 19 if code != multistep.ActionContinue { 20 t.Errorf("Expected ActionContinue(%d), but got=%d", multistep.ActionContinue, code) 21 } 22 } 23 24 func TestProcessStepResultShouldHaltOnError(t *testing.T) { 25 stateBag := new(multistep.BasicStateBag) 26 isSaidError := false 27 28 code := processStepResult(fmt.Errorf("boom"), func(error) { isSaidError = true }, stateBag) 29 if _, ok := stateBag.GetOk(constants.Error); !ok { 30 t.Errorf("Error was non nil, but was not in the state bag.") 31 } 32 33 if !isSaidError { 34 t.Errorf("Expected error to be said, but it was not.") 35 } 36 37 if code != multistep.ActionHalt { 38 t.Errorf("Expected ActionHalt(%d), but got=%d", multistep.ActionHalt, code) 39 } 40 }