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"
|
2018-01-29 08:41:22 -05:00
|
|
|
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2018-01-11 04:57:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepGetRootPasswordShouldFailIfOperationGetRootPasswordFails(t *testing.T) {
|
|
|
|
var testSubject = &StepGetRootPassword{
|
|
|
|
GetRootPassword: func(string, string) (string, error) { return "", fmt.Errorf("!! Unit Test FAIL !!") },
|
|
|
|
Say: func(message string) {},
|
|
|
|
Error: func(e error) {},
|
2018-12-21 03:53:52 -05:00
|
|
|
Config: &Config{},
|
2018-01-11 04:57:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
stateBag := DeleteTestStateBagStepGetRootPassword()
|
|
|
|
|
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 TestStepGetRootPasswordShouldPassIfOperationGetRootPasswordPasses(t *testing.T) {
|
|
|
|
var testSubject = &StepGetRootPassword{
|
|
|
|
GetRootPassword: func(string, string) (string, error) { return "a", nil },
|
|
|
|
Say: func(message string) {},
|
|
|
|
Error: func(e error) {},
|
2018-12-21 03:53:52 -05:00
|
|
|
Config: &Config{},
|
2018-01-11 04:57:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
stateBag := DeleteTestStateBagStepGetRootPassword()
|
|
|
|
|
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 DeleteTestStateBagStepGetRootPassword() multistep.StateBag {
|
|
|
|
stateBag := new(multistep.BasicStateBag)
|
|
|
|
|
|
|
|
stateBag.Put("LoginKey", &LoginKey{"a", "b"})
|
|
|
|
stateBag.Put("InstanceNo", "a")
|
|
|
|
|
|
|
|
return stateBag
|
|
|
|
}
|