packer-cn/builder/ncloud/step_delete_block_storage_instance_test.go

60 lines
1.8 KiB
Go
Raw Normal View History

2018-01-11 18:57:53 +09:00
package ncloud
import (
2018-01-30 10:20:02 +09:00
"context"
2018-01-11 18:57:53 +09:00
"fmt"
"testing"
2020-12-17 13:29:25 -08:00
"github.com/hashicorp/packer-plugin-sdk/multistep"
2018-01-11 18:57:53 +09:00
)
func TestStepDeleteBlockStorageInstanceShouldFailIfOperationDeleteBlockStorageInstanceFails(t *testing.T) {
2021-03-23 16:35:36 +09:00
var testSubject = &StepDeleteBlockStorage{
DeleteBlockStorage: func(blockStorageNo string) error { return fmt.Errorf("!! Unit Test FAIL !!") },
Say: func(message string) {},
Error: func(e error) {},
Config: &Config{BlockStorageSize: 10},
2018-01-11 18:57:53 +09:00
}
stateBag := createTestStateBagStepDeleteBlockStorageInstance()
2018-01-30 10:20:02 +09:00
var result = testSubject.Run(context.Background(), stateBag)
2018-01-11 18:57:53 +09:00
if result != multistep.ActionHalt {
t.Fatalf("Expected the step to return 'ActionHalt', but got '%d'.", result)
}
2021-03-23 16:35:36 +09:00
if _, ok := stateBag.GetOk("error"); ok == false {
2018-01-11 18:57:53 +09:00
t.Fatal("Expected the step to set stateBag['Error'], but it was not.")
}
}
func TestStepDeleteBlockStorageInstanceShouldPassIfOperationDeleteBlockStorageInstancePasses(t *testing.T) {
2021-03-23 16:35:36 +09:00
var testSubject = &StepDeleteBlockStorage{
DeleteBlockStorage: func(blockStorageNo string) error { return nil },
Say: func(message string) {},
Error: func(e error) {},
Config: &Config{BlockStorageSize: 10},
2018-01-11 18:57:53 +09:00
}
stateBag := createTestStateBagStepDeleteBlockStorageInstance()
2018-01-30 10:20:02 +09:00
var result = testSubject.Run(context.Background(), stateBag)
2018-01-11 18:57:53 +09:00
if result != multistep.ActionContinue {
t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result)
}
2021-03-23 16:35:36 +09:00
if _, ok := stateBag.GetOk("error"); ok == true {
2018-01-11 18:57:53 +09:00
t.Fatalf("Expected the step to not set stateBag['Error'], but it was.")
}
}
func createTestStateBagStepDeleteBlockStorageInstance() multistep.StateBag {
stateBag := new(multistep.BasicStateBag)
2021-03-23 16:35:36 +09:00
stateBag.Put("instance_no", "1")
2018-01-11 18:57:53 +09:00
return stateBag
}