2016-04-21 19:50:03 -04:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
2016-05-06 23:32:18 -04:00
|
|
|
// Licensed under the MIT License. See the LICENSE file in builder/azure for license information.
|
2016-04-21 19:50:03 -04:00
|
|
|
|
|
|
|
package arm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/builder/azure/common"
|
|
|
|
"github.com/hashicorp/packer/builder/azure/common/constants"
|
2016-05-18 20:25:57 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2016-04-21 19:50:03 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProcessStepResultShouldContinueForNonErrors(t *testing.T) {
|
|
|
|
stateBag := new(multistep.BasicStateBag)
|
|
|
|
|
2016-07-16 01:23:53 -04:00
|
|
|
code := processStepResult(nil, func(error) { t.Fatal("Should not be called!") }, stateBag)
|
2016-04-21 19:50:03 -04:00
|
|
|
if _, ok := stateBag.GetOk(constants.Error); ok {
|
|
|
|
t.Errorf("Error was nil, but was still in the state bag.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if code != multistep.ActionContinue {
|
|
|
|
t.Errorf("Expected ActionContinue(%d), but got=%d", multistep.ActionContinue, code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessStepResultShouldHaltOnError(t *testing.T) {
|
|
|
|
stateBag := new(multistep.BasicStateBag)
|
|
|
|
isSaidError := false
|
|
|
|
|
|
|
|
code := processStepResult(fmt.Errorf("boom"), func(error) { isSaidError = true }, stateBag)
|
|
|
|
if _, ok := stateBag.GetOk(constants.Error); !ok {
|
|
|
|
t.Errorf("Error was non nil, but was not in the state bag.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isSaidError {
|
|
|
|
t.Errorf("Expected error to be said, but it was not.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if code != multistep.ActionHalt {
|
|
|
|
t.Errorf("Expected ActionHalt(%d), but got=%d", multistep.ActionHalt, code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessStepResultShouldContinueOnSuccessfulTask(t *testing.T) {
|
|
|
|
stateBag := new(multistep.BasicStateBag)
|
|
|
|
result := common.InterruptibleTaskResult{
|
|
|
|
IsCancelled: false,
|
|
|
|
Err: nil,
|
|
|
|
}
|
|
|
|
|
2016-07-16 01:23:53 -04:00
|
|
|
code := processInterruptibleResult(result, func(error) { t.Fatal("Should not be called!") }, stateBag)
|
2016-04-21 19:50:03 -04:00
|
|
|
if _, ok := stateBag.GetOk(constants.Error); ok {
|
|
|
|
t.Errorf("Error was nil, but was still in the state bag.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if code != multistep.ActionContinue {
|
|
|
|
t.Errorf("Expected ActionContinue(%d), but got=%d", multistep.ActionContinue, code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessStepResultShouldHaltWhenTaskIsCancelled(t *testing.T) {
|
|
|
|
stateBag := new(multistep.BasicStateBag)
|
|
|
|
result := common.InterruptibleTaskResult{
|
|
|
|
IsCancelled: true,
|
|
|
|
Err: nil,
|
|
|
|
}
|
|
|
|
|
2016-07-16 01:23:53 -04:00
|
|
|
code := processInterruptibleResult(result, func(error) { t.Fatal("Should not be called!") }, stateBag)
|
2016-04-21 19:50:03 -04:00
|
|
|
if _, ok := stateBag.GetOk(constants.Error); ok {
|
|
|
|
t.Errorf("Error was nil, but was still in the state bag.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if code != multistep.ActionHalt {
|
|
|
|
t.Errorf("Expected ActionHalt(%d), but got=%d", multistep.ActionHalt, code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessStepResultShouldHaltOnTaskError(t *testing.T) {
|
|
|
|
stateBag := new(multistep.BasicStateBag)
|
|
|
|
isSaidError := false
|
|
|
|
result := common.InterruptibleTaskResult{
|
|
|
|
IsCancelled: false,
|
|
|
|
Err: fmt.Errorf("boom"),
|
|
|
|
}
|
|
|
|
|
|
|
|
code := processInterruptibleResult(result, func(error) { isSaidError = true }, stateBag)
|
|
|
|
if _, ok := stateBag.GetOk(constants.Error); !ok {
|
|
|
|
t.Errorf("Error was *not* nil, but was not in the state bag.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isSaidError {
|
|
|
|
t.Errorf("Expected error to be said, but it was not.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if code != multistep.ActionHalt {
|
|
|
|
t.Errorf("Expected ActionHalt(%d), but got=%d", multistep.ActionHalt, code)
|
|
|
|
}
|
|
|
|
}
|