packer-cn/builder/ncloud/step_create_login_key_test.go

54 lines
1.5 KiB
Go
Raw Normal View History

2018-01-11 04:57:53 -05:00
package ncloud
import (
"fmt"
"github.com/mitchellh/multistep"
"testing"
)
func TestStepCreateLoginKeyShouldFailIfOperationCreateLoginKeyFails(t *testing.T) {
var testSubject = &StepCreateLoginKey{
CreateLoginKey: func() (*LoginKey, error) { return nil, fmt.Errorf("!! Unit Test FAIL !!") },
Say: func(message string) {},
Error: func(e error) {},
}
stateBag := createTestStateBagStepCreateLoginKey()
var result = testSubject.Run(stateBag)
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 TestStepCreateLoginKeyShouldPassIfOperationCreateLoginKeyPasses(t *testing.T) {
var testSubject = &StepCreateLoginKey{
CreateLoginKey: func() (*LoginKey, error) { return &LoginKey{"a", "b"}, nil },
Say: func(message string) {},
Error: func(e error) {},
}
stateBag := createTestStateBagStepCreateLoginKey()
var result = testSubject.Run(stateBag)
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 createTestStateBagStepCreateLoginKey() multistep.StateBag {
stateBag := new(multistep.BasicStateBag)
return stateBag
}