packer-cn/builder/ncloud/step_create_block_storage_i...

66 lines
2.0 KiB
Go
Raw Normal View History

2018-01-11 04:57:53 -05:00
package ncloud
import (
2018-01-29 20:20:02 -05:00
"context"
2018-01-11 04:57:53 -05:00
"fmt"
"testing"
2020-12-17 16:29:25 -05:00
"github.com/hashicorp/packer-plugin-sdk/multistep"
2018-01-11 04:57:53 -05:00
)
func TestStepCreateBlockStorageInstanceShouldFailIfOperationCreateBlockStorageInstanceFails(t *testing.T) {
var testSubject = &StepCreateBlockStorageInstance{
CreateBlockStorageInstance: func(serverInstanceNo string) (*string, error) { return nil, fmt.Errorf("!! Unit Test FAIL !!") },
2018-08-24 18:56:44 -04:00
Say: func(message string) {},
Error: func(e error) {},
Config: new(Config),
2018-01-11 04:57:53 -05:00
}
testSubject.Config.BlockStorageSize = 10
stateBag := createTestStateBagStepCreateBlockStorageInstance()
2018-01-29 20:20:02 -05:00
var result = testSubject.Run(context.Background(), stateBag)
2018-01-11 04:57:53 -05:00
if result != multistep.ActionHalt {
t.Fatalf("Expected the step to return 'ActionHalt', but got '%d'.", result)
}
if _, ok := stateBag.GetOk("Error"); ok == false {
t.Fatal("Expected the step to set stateBag['Error'], but it was not.")
}
}
func TestStepCreateBlockStorageInstanceShouldPassIfOperationCreateBlockStorageInstancePasses(t *testing.T) {
var instanceNo = "a"
2018-01-11 04:57:53 -05:00
var testSubject = &StepCreateBlockStorageInstance{
CreateBlockStorageInstance: func(serverInstanceNo string) (*string, error) { return &instanceNo, nil },
2018-08-24 18:56:44 -04:00
Say: func(message string) {},
Error: func(e error) {},
Config: new(Config),
2018-01-11 04:57:53 -05:00
}
testSubject.Config.BlockStorageSize = 10
stateBag := createTestStateBagStepCreateBlockStorageInstance()
2018-01-29 20:20:02 -05:00
var result = testSubject.Run(context.Background(), stateBag)
2018-01-11 04:57:53 -05:00
if result != multistep.ActionContinue {
t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result)
}
if _, ok := stateBag.GetOk("Error"); ok == true {
t.Fatalf("Expected the step to not set stateBag['Error'], but it was.")
}
}
func createTestStateBagStepCreateBlockStorageInstance() multistep.StateBag {
stateBag := new(multistep.BasicStateBag)
stateBag.Put("InstanceNo", "a")
return stateBag
}