github.com/timsutton/packer@v1.3.2/builder/ncloud/step_delete_block_storage_instance_test.go (about) 1 package ncloud 2 3 import ( 4 "context" 5 "fmt" 6 "testing" 7 8 "github.com/hashicorp/packer/helper/multistep" 9 ) 10 11 func TestStepDeleteBlockStorageInstanceShouldFailIfOperationDeleteBlockStorageInstanceFails(t *testing.T) { 12 var testSubject = &StepDeleteBlockStorageInstance{ 13 DeleteBlockStorageInstance: func(blockStorageInstanceNo string) error { return fmt.Errorf("!! Unit Test FAIL !!") }, 14 Say: func(message string) {}, 15 Error: func(e error) {}, 16 Config: &Config{BlockStorageSize: 10}, 17 } 18 19 stateBag := createTestStateBagStepDeleteBlockStorageInstance() 20 21 var result = testSubject.Run(context.Background(), stateBag) 22 23 if result != multistep.ActionHalt { 24 t.Fatalf("Expected the step to return 'ActionHalt', but got '%d'.", result) 25 } 26 27 if _, ok := stateBag.GetOk("Error"); ok == false { 28 t.Fatal("Expected the step to set stateBag['Error'], but it was not.") 29 } 30 } 31 32 func TestStepDeleteBlockStorageInstanceShouldPassIfOperationDeleteBlockStorageInstancePasses(t *testing.T) { 33 var testSubject = &StepDeleteBlockStorageInstance{ 34 DeleteBlockStorageInstance: func(blockStorageInstanceNo string) error { return nil }, 35 Say: func(message string) {}, 36 Error: func(e error) {}, 37 Config: &Config{BlockStorageSize: 10}, 38 } 39 40 stateBag := createTestStateBagStepDeleteBlockStorageInstance() 41 42 var result = testSubject.Run(context.Background(), stateBag) 43 44 if result != multistep.ActionContinue { 45 t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result) 46 } 47 48 if _, ok := stateBag.GetOk("Error"); ok == true { 49 t.Fatalf("Expected the step to not set stateBag['Error'], but it was.") 50 } 51 } 52 53 func createTestStateBagStepDeleteBlockStorageInstance() multistep.StateBag { 54 stateBag := new(multistep.BasicStateBag) 55 56 stateBag.Put("InstanceNo", "1") 57 58 return stateBag 59 }