make tests pass again

This commit is contained in:
Paul Meyer 2018-04-11 08:25:33 -07:00
parent 09ce3c9803
commit a3fb24639a
23 changed files with 96 additions and 91 deletions

View File

@ -16,25 +16,25 @@ func TestNewAuthenticate(t *testing.T) {
t.Fatalf(err.Error()) t.Fatalf(err.Error())
} }
if spn.Token.AccessToken != "" { if spn.Token().AccessToken != "" {
t.Errorf("spn.Token.AccessToken: expected=\"\", actual=%s", spn.Token.AccessToken) t.Errorf("spn.Token().AccessToken: expected=\"\", actual=%s", spn.Token().AccessToken)
} }
if spn.Token.RefreshToken != "" { if spn.Token().RefreshToken != "" {
t.Errorf("spn.Token.RefreshToken: expected=\"\", actual=%s", spn.Token.RefreshToken) t.Errorf("spn.Token().RefreshToken: expected=\"\", actual=%s", spn.Token().RefreshToken)
} }
if spn.Token.ExpiresIn != "" { if spn.Token().ExpiresIn != "" {
t.Errorf("spn.Token.ExpiresIn: expected=\"\", actual=%s", spn.Token.ExpiresIn) t.Errorf("spn.Token().ExpiresIn: expected=\"\", actual=%s", spn.Token().ExpiresIn)
} }
if spn.Token.ExpiresOn != "" { if spn.Token().ExpiresOn != "" {
t.Errorf("spn.Token.ExpiresOn: expected=\"\", actual=%s", spn.Token.ExpiresOn) t.Errorf("spn.Token().ExpiresOn: expected=\"\", actual=%s", spn.Token().ExpiresOn)
} }
if spn.Token.NotBefore != "" { if spn.Token().NotBefore != "" {
t.Errorf("spn.Token.NotBefore: expected=\"\", actual=%s", spn.Token.NotBefore) t.Errorf("spn.Token().NotBefore: expected=\"\", actual=%s", spn.Token().NotBefore)
} }
if spn.Token.Resource != "" { if spn.Token().Resource != "" {
t.Errorf("spn.Token.Resource: expected=\"\", actual=%s", spn.Token.Resource) t.Errorf("spn.Token().Resource: expected=\"\", actual=%s", spn.Token().Resource)
} }
if spn.Token.Type != "" { if spn.Token().Type != "" {
t.Errorf("spn.Token.Type: expected=\"\", actual=%s", spn.Token.Type) t.Errorf("spn.Token().Type: expected=\"\", actual=%s", spn.Token().Type)
} }
} }

View File

@ -311,7 +311,7 @@ func (b *Builder) configureStateBag(stateBag multistep.StateBag) {
stateBag.Put(constants.AuthorizedKey, b.config.sshAuthorizedKey) stateBag.Put(constants.AuthorizedKey, b.config.sshAuthorizedKey)
stateBag.Put(constants.PrivateKey, b.config.sshPrivateKey) stateBag.Put(constants.PrivateKey, b.config.sshPrivateKey)
stateBag.Put(constants.ArmTags, &b.config.AzureTags) stateBag.Put(constants.ArmTags, b.config.AzureTags)
stateBag.Put(constants.ArmComputeName, b.config.tmpComputeName) stateBag.Put(constants.ArmComputeName, b.config.tmpComputeName)
stateBag.Put(constants.ArmDeploymentName, b.config.tmpDeploymentName) stateBag.Put(constants.ArmDeploymentName, b.config.tmpDeploymentName)
if b.config.OSType == constants.Target_Windows { if b.config.OSType == constants.Target_Windows {

View File

@ -6,7 +6,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
) )
@ -86,7 +86,7 @@ func TestConfigShouldBeAbleToOverrideDefaultedValues(t *testing.T) {
t.Errorf("Expected 'vm_size' to be set to 'override_vm_size', but found %q!", c.VMSize) t.Errorf("Expected 'vm_size' to be set to 'override_vm_size', but found %q!", c.VMSize)
} }
if c.managedImageStorageAccountType != compute.PremiumLRS { if c.managedImageStorageAccountType != compute.StorageAccountTypesPremiumLRS {
t.Errorf("Expected 'managed_image_storage_account_type' to be set to 'Premium_LRS', but found %q!", c.managedImageStorageAccountType) t.Errorf("Expected 'managed_image_storage_account_type' to be set to 'Premium_LRS', but found %q!", c.managedImageStorageAccountType)
} }
} }

View File

@ -5,14 +5,14 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
) )
func TestStepCaptureImageShouldFailIfCaptureFails(t *testing.T) { func TestStepCaptureImageShouldFailIfCaptureFails(t *testing.T) {
var testSubject = &StepCaptureImage{ var testSubject = &StepCaptureImage{
captureVhd: func(string, string, *compute.VirtualMachineCaptureParameters, <-chan struct{}) error { captureVhd: func(context.Context, string, string, *compute.VirtualMachineCaptureParameters) error {
return fmt.Errorf("!! Unit Test FAIL !!") return fmt.Errorf("!! Unit Test FAIL !!")
}, },
generalizeVM: func(string, string) error { generalizeVM: func(string, string) error {
@ -39,7 +39,7 @@ func TestStepCaptureImageShouldFailIfCaptureFails(t *testing.T) {
func TestStepCaptureImageShouldPassIfCapturePasses(t *testing.T) { func TestStepCaptureImageShouldPassIfCapturePasses(t *testing.T) {
var testSubject = &StepCaptureImage{ var testSubject = &StepCaptureImage{
captureVhd: func(string, string, *compute.VirtualMachineCaptureParameters, <-chan struct{}) error { return nil }, captureVhd: func(context.Context, string, string, *compute.VirtualMachineCaptureParameters) error { return nil },
generalizeVM: func(string, string) error { generalizeVM: func(string, string) error {
return nil return nil
}, },
@ -74,7 +74,7 @@ func TestStepCaptureImageShouldTakeStepArgumentsFromStateBag(t *testing.T) {
} }
var testSubject = &StepCaptureImage{ var testSubject = &StepCaptureImage{
captureVhd: func(resourceGroupName string, computeName string, parameters *compute.VirtualMachineCaptureParameters, cancelCh <-chan struct{}) error { captureVhd: func(_ context.Context, resourceGroupName string, computeName string, parameters *compute.VirtualMachineCaptureParameters) error {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualComputeName = computeName actualComputeName = computeName
actualVirtualMachineCaptureParameters = parameters actualVirtualMachineCaptureParameters = parameters

View File

@ -61,7 +61,7 @@ func (s *StepCreateResourceGroup) Run(ctx context.Context, state multistep.State
var resourceGroupName = state.Get(constants.ArmResourceGroupName).(string) var resourceGroupName = state.Get(constants.ArmResourceGroupName).(string)
var location = state.Get(constants.ArmLocation).(string) var location = state.Get(constants.ArmLocation).(string)
var tags = *state.Get(constants.ArmTags).(*map[string]*string) var tags = state.Get(constants.ArmTags).(map[string]*string)
exists, err := s.exists(ctx, resourceGroupName) exists, err := s.exists(ctx, resourceGroupName)
if err != nil { if err != nil {

View File

@ -20,12 +20,12 @@ func TestStepCreateResourceGroupShouldFailIfBothGroupNames(t *testing.T) {
"tag01": &value, "tag01": &value,
} }
stateBag.Put(constants.ArmTags, &tags) stateBag.Put(constants.ArmTags, tags)
var testSubject = &StepCreateResourceGroup{ var testSubject = &StepCreateResourceGroup{
create: func(string, string, *map[string]*string) error { return nil }, create: func(context.Context, string, string, map[string]*string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
exists: func(string) (bool, error) { return false, nil }, exists: func(context.Context, string) (bool, error) { return false, nil },
} }
var result = testSubject.Run(context.Background(), stateBag) var result = testSubject.Run(context.Background(), stateBag)
if result != multistep.ActionHalt { if result != multistep.ActionHalt {
@ -39,10 +39,12 @@ func TestStepCreateResourceGroupShouldFailIfBothGroupNames(t *testing.T) {
func TestStepCreateResourceGroupShouldFailIfCreateFails(t *testing.T) { func TestStepCreateResourceGroupShouldFailIfCreateFails(t *testing.T) {
var testSubject = &StepCreateResourceGroup{ var testSubject = &StepCreateResourceGroup{
create: func(string, string, *map[string]*string) error { return fmt.Errorf("!! Unit Test FAIL !!") }, create: func(context.Context, string, string, map[string]*string) error {
return fmt.Errorf("!! Unit Test FAIL !!")
},
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
exists: func(string) (bool, error) { return false, nil }, exists: func(context.Context, string) (bool, error) { return false, nil },
} }
stateBag := createTestStateBagStepCreateResourceGroup() stateBag := createTestStateBagStepCreateResourceGroup()
@ -59,10 +61,10 @@ func TestStepCreateResourceGroupShouldFailIfCreateFails(t *testing.T) {
func TestStepCreateResourceGroupShouldFailIfExistsFails(t *testing.T) { func TestStepCreateResourceGroupShouldFailIfExistsFails(t *testing.T) {
var testSubject = &StepCreateResourceGroup{ var testSubject = &StepCreateResourceGroup{
create: func(string, string, *map[string]*string) error { return nil }, create: func(context.Context, string, string, map[string]*string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
exists: func(string) (bool, error) { return false, errors.New("FAIL") }, exists: func(context.Context, string) (bool, error) { return false, errors.New("FAIL") },
} }
stateBag := createTestStateBagStepCreateResourceGroup() stateBag := createTestStateBagStepCreateResourceGroup()
@ -79,10 +81,10 @@ func TestStepCreateResourceGroupShouldFailIfExistsFails(t *testing.T) {
func TestStepCreateResourceGroupShouldPassIfCreatePasses(t *testing.T) { func TestStepCreateResourceGroupShouldPassIfCreatePasses(t *testing.T) {
var testSubject = &StepCreateResourceGroup{ var testSubject = &StepCreateResourceGroup{
create: func(string, string, *map[string]*string) error { return nil }, create: func(context.Context, string, string, map[string]*string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
exists: func(string) (bool, error) { return false, nil }, exists: func(context.Context, string) (bool, error) { return false, nil },
} }
stateBag := createTestStateBagStepCreateResourceGroup() stateBag := createTestStateBagStepCreateResourceGroup()
@ -100,10 +102,10 @@ func TestStepCreateResourceGroupShouldPassIfCreatePasses(t *testing.T) {
func TestStepCreateResourceGroupShouldTakeStepArgumentsFromStateBag(t *testing.T) { func TestStepCreateResourceGroupShouldTakeStepArgumentsFromStateBag(t *testing.T) {
var actualResourceGroupName string var actualResourceGroupName string
var actualLocation string var actualLocation string
var actualTags *map[string]*string var actualTags map[string]*string
var testSubject = &StepCreateResourceGroup{ var testSubject = &StepCreateResourceGroup{
create: func(resourceGroupName string, location string, tags *map[string]*string) error { create: func(_ context.Context, resourceGroupName string, location string, tags map[string]*string) error {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualLocation = location actualLocation = location
actualTags = tags actualTags = tags
@ -111,7 +113,7 @@ func TestStepCreateResourceGroupShouldTakeStepArgumentsFromStateBag(t *testing.T
}, },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
exists: func(string) (bool, error) { return false, nil }, exists: func(context.Context, string) (bool, error) { return false, nil },
} }
stateBag := createTestStateBagStepCreateResourceGroup() stateBag := createTestStateBagStepCreateResourceGroup()
@ -123,7 +125,7 @@ func TestStepCreateResourceGroupShouldTakeStepArgumentsFromStateBag(t *testing.T
var expectedResourceGroupName = stateBag.Get(constants.ArmResourceGroupName).(string) var expectedResourceGroupName = stateBag.Get(constants.ArmResourceGroupName).(string)
var expectedLocation = stateBag.Get(constants.ArmLocation).(string) var expectedLocation = stateBag.Get(constants.ArmLocation).(string)
var expectedTags = stateBag.Get(constants.ArmTags).(*map[string]*string) var expectedTags = stateBag.Get(constants.ArmTags).(map[string]*string)
if actualResourceGroupName != expectedResourceGroupName { if actualResourceGroupName != expectedResourceGroupName {
t.Fatal("Expected the step to source 'constants.ArmResourceGroupName' from the state bag, but it did not.") t.Fatal("Expected the step to source 'constants.ArmResourceGroupName' from the state bag, but it did not.")
@ -133,7 +135,7 @@ func TestStepCreateResourceGroupShouldTakeStepArgumentsFromStateBag(t *testing.T
t.Fatal("Expected the step to source 'constants.ArmResourceGroupName' from the state bag, but it did not.") t.Fatal("Expected the step to source 'constants.ArmResourceGroupName' from the state bag, but it did not.")
} }
if len(*expectedTags) != len(*actualTags) && *(*expectedTags)["tag01"] != *(*actualTags)["tag01"] { if len(expectedTags) != len(actualTags) && expectedTags["tag01"] != actualTags["tag01"] {
t.Fatal("Expected the step to source 'constants.ArmTags' from the state bag, but it did not.") t.Fatal("Expected the step to source 'constants.ArmTags' from the state bag, but it did not.")
} }
@ -145,10 +147,12 @@ func TestStepCreateResourceGroupShouldTakeStepArgumentsFromStateBag(t *testing.T
func TestStepCreateResourceGroupMarkShouldFailIfTryingExistingButDoesntExist(t *testing.T) { func TestStepCreateResourceGroupMarkShouldFailIfTryingExistingButDoesntExist(t *testing.T) {
var testSubject = &StepCreateResourceGroup{ var testSubject = &StepCreateResourceGroup{
create: func(string, string, *map[string]*string) error { return fmt.Errorf("!! Unit Test FAIL !!") }, create: func(context.Context, string, string, map[string]*string) error {
return fmt.Errorf("!! Unit Test FAIL !!")
},
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
exists: func(string) (bool, error) { return false, nil }, exists: func(context.Context, string) (bool, error) { return false, nil },
} }
stateBag := createTestExistingStateBagStepCreateResourceGroup() stateBag := createTestExistingStateBagStepCreateResourceGroup()
@ -165,10 +169,12 @@ func TestStepCreateResourceGroupMarkShouldFailIfTryingExistingButDoesntExist(t *
func TestStepCreateResourceGroupMarkShouldFailIfTryingTempButExist(t *testing.T) { func TestStepCreateResourceGroupMarkShouldFailIfTryingTempButExist(t *testing.T) {
var testSubject = &StepCreateResourceGroup{ var testSubject = &StepCreateResourceGroup{
create: func(string, string, *map[string]*string) error { return fmt.Errorf("!! Unit Test FAIL !!") }, create: func(context.Context, string, string, map[string]*string) error {
return fmt.Errorf("!! Unit Test FAIL !!")
},
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
exists: func(string) (bool, error) { return true, nil }, exists: func(context.Context, string) (bool, error) { return true, nil },
} }
stateBag := createTestStateBagStepCreateResourceGroup() stateBag := createTestStateBagStepCreateResourceGroup()
@ -195,7 +201,7 @@ func createTestStateBagStepCreateResourceGroup() multistep.StateBag {
"tag01": &value, "tag01": &value,
} }
stateBag.Put(constants.ArmTags, &tags) stateBag.Put(constants.ArmTags, tags)
return stateBag return stateBag
} }
@ -211,6 +217,6 @@ func createTestExistingStateBagStepCreateResourceGroup() multistep.StateBag {
"tag01": &value, "tag01": &value,
} }
stateBag.Put(constants.ArmTags, &tags) stateBag.Put(constants.ArmTags, tags)
return stateBag return stateBag
} }

View File

@ -13,7 +13,7 @@ import (
func TestStepDeleteAdditionalDiskShouldFailIfGetFails(t *testing.T) { func TestStepDeleteAdditionalDiskShouldFailIfGetFails(t *testing.T) {
var testSubject = &StepDeleteAdditionalDisk{ var testSubject = &StepDeleteAdditionalDisk{
delete: func(string, string) error { return fmt.Errorf("!! Unit Test FAIL !!") }, delete: func(string, string) error { return fmt.Errorf("!! Unit Test FAIL !!") },
deleteManaged: func(string, string) error { return nil }, deleteManaged: func(context.Context, string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
} }
@ -110,7 +110,7 @@ func TestStepDeleteAdditionalDiskShouldFailIfVHDNameCannotBeURLParsed(t *testing
delete: func(string, string) error { return nil }, delete: func(string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
deleteManaged: func(string, string) error { return nil }, deleteManaged: func(context.Context, string, string) error { return nil },
} }
// Invalid URL per https://golang.org/src/net/url/url_test.go // Invalid URL per https://golang.org/src/net/url/url_test.go
@ -130,7 +130,7 @@ func TestStepDeleteAdditionalDiskShouldFailIfVHDNameIsTooShort(t *testing.T) {
delete: func(string, string) error { return nil }, delete: func(string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
deleteManaged: func(string, string) error { return nil }, deleteManaged: func(context.Context, string, string) error { return nil },
} }
stateBag := DeleteTestStateBagStepDeleteAdditionalDisk([]string{"storage.blob.core.windows.net/abc"}) stateBag := DeleteTestStateBagStepDeleteAdditionalDisk([]string{"storage.blob.core.windows.net/abc"})
@ -173,7 +173,7 @@ func TestStepDeleteAdditionalDiskShouldFailIfManagedDiskInExistingResourceGroupF
delete: func(string, string) error { return nil }, delete: func(string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
deleteManaged: func(string, string) error { return errors.New("UNIT TEST FAIL!") }, deleteManaged: func(context.Context, string, string) error { return errors.New("UNIT TEST FAIL!") },
} }
stateBag := new(multistep.BasicStateBag) stateBag := new(multistep.BasicStateBag)
@ -197,7 +197,7 @@ func TestStepDeleteAdditionalDiskShouldFailIfManagedDiskInExistingResourceGroupI
delete: func(string, string) error { return nil }, delete: func(string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
deleteManaged: func(string, string) error { return nil }, deleteManaged: func(context.Context, string, string) error { return nil },
} }
stateBag := new(multistep.BasicStateBag) stateBag := new(multistep.BasicStateBag)

View File

@ -13,7 +13,7 @@ import (
func TestStepDeleteOSDiskShouldFailIfGetFails(t *testing.T) { func TestStepDeleteOSDiskShouldFailIfGetFails(t *testing.T) {
var testSubject = &StepDeleteOSDisk{ var testSubject = &StepDeleteOSDisk{
delete: func(string, string) error { return fmt.Errorf("!! Unit Test FAIL !!") }, delete: func(string, string) error { return fmt.Errorf("!! Unit Test FAIL !!") },
deleteManaged: func(string, string) error { return nil }, deleteManaged: func(context.Context, string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
} }
@ -110,7 +110,7 @@ func TestStepDeleteOSDiskShouldFailIfVHDNameCannotBeURLParsed(t *testing.T) {
delete: func(string, string) error { return nil }, delete: func(string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
deleteManaged: func(string, string) error { return nil }, deleteManaged: func(context.Context, string, string) error { return nil },
} }
// Invalid URL per https://golang.org/src/net/url/url_test.go // Invalid URL per https://golang.org/src/net/url/url_test.go
@ -130,7 +130,7 @@ func TestStepDeleteOSDiskShouldFailIfVHDNameIsTooShort(t *testing.T) {
delete: func(string, string) error { return nil }, delete: func(string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
deleteManaged: func(string, string) error { return nil }, deleteManaged: func(context.Context, string, string) error { return nil },
} }
stateBag := DeleteTestStateBagStepDeleteOSDisk("storage.blob.core.windows.net/abc") stateBag := DeleteTestStateBagStepDeleteOSDisk("storage.blob.core.windows.net/abc")
@ -173,7 +173,7 @@ func TestStepDeleteOSDiskShouldFailIfManagedDiskInExistingResourceGroupFailsToDe
delete: func(string, string) error { return nil }, delete: func(string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
deleteManaged: func(string, string) error { return errors.New("UNIT TEST FAIL!") }, deleteManaged: func(context.Context, string, string) error { return errors.New("UNIT TEST FAIL!") },
} }
stateBag := new(multistep.BasicStateBag) stateBag := new(multistep.BasicStateBag)
@ -197,7 +197,7 @@ func TestStepDeleteOSDiskShouldFailIfManagedDiskInExistingResourceGroupIsDeleted
delete: func(string, string) error { return nil }, delete: func(string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
deleteManaged: func(string, string) error { return nil }, deleteManaged: func(context.Context, string, string) error { return nil },
} }
stateBag := new(multistep.BasicStateBag) stateBag := new(multistep.BasicStateBag)

View File

@ -11,7 +11,7 @@ import (
func TestStepDeleteResourceGroupShouldFailIfDeleteFails(t *testing.T) { func TestStepDeleteResourceGroupShouldFailIfDeleteFails(t *testing.T) {
var testSubject = &StepDeleteResourceGroup{ var testSubject = &StepDeleteResourceGroup{
delete: func(multistep.StateBag, string, <-chan struct{}) error { return fmt.Errorf("!! Unit Test FAIL !!") }, delete: func(context.Context, multistep.StateBag, string) error { return fmt.Errorf("!! Unit Test FAIL !!") },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
} }
@ -30,7 +30,7 @@ func TestStepDeleteResourceGroupShouldFailIfDeleteFails(t *testing.T) {
func TestStepDeleteResourceGroupShouldPassIfDeletePasses(t *testing.T) { func TestStepDeleteResourceGroupShouldPassIfDeletePasses(t *testing.T) {
var testSubject = &StepDeleteResourceGroup{ var testSubject = &StepDeleteResourceGroup{
delete: func(multistep.StateBag, string, <-chan struct{}) error { return nil }, delete: func(context.Context, multistep.StateBag, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
} }
@ -49,7 +49,7 @@ func TestStepDeleteResourceGroupShouldPassIfDeletePasses(t *testing.T) {
func TestStepDeleteResourceGroupShouldDeleteStateBagArmResourceGroupCreated(t *testing.T) { func TestStepDeleteResourceGroupShouldDeleteStateBagArmResourceGroupCreated(t *testing.T) {
var testSubject = &StepDeleteResourceGroup{ var testSubject = &StepDeleteResourceGroup{
delete: func(s multistep.StateBag, resourceGroupName string, cancelCh <-chan struct{}) error { delete: func(context.Context, multistep.StateBag, string) error {
return nil return nil
}, },
say: func(message string) {}, say: func(message string) {},

View File

@ -11,7 +11,7 @@ import (
func TestStepDeployTemplateShouldFailIfDeployFails(t *testing.T) { func TestStepDeployTemplateShouldFailIfDeployFails(t *testing.T) {
var testSubject = &StepDeployTemplate{ var testSubject = &StepDeployTemplate{
deploy: func(string, string, <-chan struct{}) error { deploy: func(context.Context, string, string) error {
return fmt.Errorf("!! Unit Test FAIL !!") return fmt.Errorf("!! Unit Test FAIL !!")
}, },
say: func(message string) {}, say: func(message string) {},
@ -32,7 +32,7 @@ func TestStepDeployTemplateShouldFailIfDeployFails(t *testing.T) {
func TestStepDeployTemplateShouldPassIfDeployPasses(t *testing.T) { func TestStepDeployTemplateShouldPassIfDeployPasses(t *testing.T) {
var testSubject = &StepDeployTemplate{ var testSubject = &StepDeployTemplate{
deploy: func(string, string, <-chan struct{}) error { return nil }, deploy: func(context.Context, string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
} }
@ -54,7 +54,7 @@ func TestStepDeployTemplateShouldTakeStepArgumentsFromStateBag(t *testing.T) {
var actualDeploymentName string var actualDeploymentName string
var testSubject = &StepDeployTemplate{ var testSubject = &StepDeployTemplate{
deploy: func(resourceGroupName string, deploymentName string, cancelCh <-chan struct{}) error { deploy: func(_ context.Context, resourceGroupName string, deploymentName string) error {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualDeploymentName = deploymentName actualDeploymentName = deploymentName
@ -90,7 +90,7 @@ func TestStepDeployTemplateDeleteImageShouldFailWhenImageUrlCannotBeParsed(t *te
name: "--deployment-name--", name: "--deployment-name--",
} }
// Invalid URL per https://golang.org/src/net/url/url_test.go // Invalid URL per https://golang.org/src/net/url/url_test.go
err := testSubject.deleteImage("image", "http://[fe80::1%en0]/", "Unit Test: ResourceGroupName") err := testSubject.deleteImage(context.TODO(), "image", "http://[fe80::1%en0]/", "Unit Test: ResourceGroupName")
if err == nil { if err == nil {
t.Fatal("Expected a failure because of the failed image name") t.Fatal("Expected a failure because of the failed image name")
} }
@ -102,7 +102,7 @@ func TestStepDeployTemplateDeleteImageShouldFailWithInvalidImage(t *testing.T) {
error: func(e error) {}, error: func(e error) {},
name: "--deployment-name--", name: "--deployment-name--",
} }
err := testSubject.deleteImage("image", "storage.blob.core.windows.net/abc", "Unit Test: ResourceGroupName") err := testSubject.deleteImage(context.TODO(), "image", "storage.blob.core.windows.net/abc", "Unit Test: ResourceGroupName")
if err == nil { if err == nil {
t.Fatal("Expected a failure because of the failed image name") t.Fatal("Expected a failure because of the failed image name")
} }

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"
@ -14,7 +14,7 @@ import (
func TestStepGetAdditionalDiskShouldFailIfGetFails(t *testing.T) { func TestStepGetAdditionalDiskShouldFailIfGetFails(t *testing.T) {
var testSubject = &StepGetDataDisk{ var testSubject = &StepGetDataDisk{
query: func(string, string) (compute.VirtualMachine, error) { query: func(context.Context, string, string) (compute.VirtualMachine, error) {
return createVirtualMachineWithDataDisksFromUri("test.vhd"), fmt.Errorf("!! Unit Test FAIL !!") return createVirtualMachineWithDataDisksFromUri("test.vhd"), fmt.Errorf("!! Unit Test FAIL !!")
}, },
say: func(message string) {}, say: func(message string) {},
@ -35,7 +35,7 @@ func TestStepGetAdditionalDiskShouldFailIfGetFails(t *testing.T) {
func TestStepGetAdditionalDiskShouldPassIfGetPasses(t *testing.T) { func TestStepGetAdditionalDiskShouldPassIfGetPasses(t *testing.T) {
var testSubject = &StepGetDataDisk{ var testSubject = &StepGetDataDisk{
query: func(string, string) (compute.VirtualMachine, error) { query: func(context.Context, string, string) (compute.VirtualMachine, error) {
return createVirtualMachineWithDataDisksFromUri("test.vhd"), nil return createVirtualMachineWithDataDisksFromUri("test.vhd"), nil
}, },
say: func(message string) {}, say: func(message string) {},
@ -59,7 +59,7 @@ func TestStepGetAdditionalDiskShouldTakeValidateArgumentsFromStateBag(t *testing
var actualComputeName string var actualComputeName string
var testSubject = &StepGetDataDisk{ var testSubject = &StepGetDataDisk{
query: func(resourceGroupName string, computeName string) (compute.VirtualMachine, error) { query: func(ctx context.Context, resourceGroupName string, computeName string) (compute.VirtualMachine, error) {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualComputeName = computeName actualComputeName = computeName

View File

@ -14,7 +14,9 @@ func TestStepGetIPAddressShouldFailIfGetFails(t *testing.T) {
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
var testSubject = &StepGetIPAddress{ var testSubject = &StepGetIPAddress{
get: func(string, string, string) (string, error) { return "", fmt.Errorf("!! Unit Test FAIL !!") }, get: func(context.Context, string, string, string) (string, error) {
return "", fmt.Errorf("!! Unit Test FAIL !!")
},
endpoint: endpoint, endpoint: endpoint,
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
@ -38,7 +40,7 @@ func TestStepGetIPAddressShouldPassIfGetPasses(t *testing.T) {
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
var testSubject = &StepGetIPAddress{ var testSubject = &StepGetIPAddress{
get: func(string, string, string) (string, error) { return "", nil }, get: func(context.Context, string, string, string) (string, error) { return "", nil },
endpoint: endpoint, endpoint: endpoint,
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
@ -65,7 +67,7 @@ func TestStepGetIPAddressShouldTakeStepArgumentsFromStateBag(t *testing.T) {
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
var testSubject = &StepGetIPAddress{ var testSubject = &StepGetIPAddress{
get: func(resourceGroupName string, ipAddressName string, nicName string) (string, error) { get: func(ctx context.Context, resourceGroupName string, ipAddressName string, nicName string) (string, error) {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualIPAddressName = ipAddressName actualIPAddressName = ipAddressName
actualNicName = nicName actualNicName = nicName

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"
@ -14,7 +14,7 @@ import (
func TestStepGetOSDiskShouldFailIfGetFails(t *testing.T) { func TestStepGetOSDiskShouldFailIfGetFails(t *testing.T) {
var testSubject = &StepGetOSDisk{ var testSubject = &StepGetOSDisk{
query: func(string, string) (compute.VirtualMachine, error) { query: func(context.Context, string, string) (compute.VirtualMachine, error) {
return createVirtualMachineFromUri("test.vhd"), fmt.Errorf("!! Unit Test FAIL !!") return createVirtualMachineFromUri("test.vhd"), fmt.Errorf("!! Unit Test FAIL !!")
}, },
say: func(message string) {}, say: func(message string) {},
@ -35,7 +35,7 @@ func TestStepGetOSDiskShouldFailIfGetFails(t *testing.T) {
func TestStepGetOSDiskShouldPassIfGetPasses(t *testing.T) { func TestStepGetOSDiskShouldPassIfGetPasses(t *testing.T) {
var testSubject = &StepGetOSDisk{ var testSubject = &StepGetOSDisk{
query: func(string, string) (compute.VirtualMachine, error) { query: func(context.Context, string, string) (compute.VirtualMachine, error) {
return createVirtualMachineFromUri("test.vhd"), nil return createVirtualMachineFromUri("test.vhd"), nil
}, },
say: func(message string) {}, say: func(message string) {},
@ -59,7 +59,7 @@ func TestStepGetOSDiskShouldTakeValidateArgumentsFromStateBag(t *testing.T) {
var actualComputeName string var actualComputeName string
var testSubject = &StepGetOSDisk{ var testSubject = &StepGetOSDisk{
query: func(resourceGroupName string, computeName string) (compute.VirtualMachine, error) { query: func(ctx context.Context, resourceGroupName string, computeName string) (compute.VirtualMachine, error) {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualComputeName = computeName actualComputeName = computeName

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/hashicorp/packer/builder/azure/common"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
@ -12,7 +11,7 @@ import (
type StepPowerOffCompute struct { type StepPowerOffCompute struct {
client *AzureClient client *AzureClient
powerOff func(ctx context.Context, resourceGroupName string, computeName string, cancelCh <-chan struct{}) error powerOff func(ctx context.Context, resourceGroupName string, computeName string) error
say func(message string) say func(message string)
error func(e error) error func(e error)
} }
@ -28,7 +27,7 @@ func NewStepPowerOffCompute(client *AzureClient, ui packer.Ui) *StepPowerOffComp
return step return step
} }
func (s *StepPowerOffCompute) powerOffCompute(ctx context.Context, resourceGroupName string, computeName string, cancelCh <-chan struct{}) error { func (s *StepPowerOffCompute) powerOffCompute(ctx context.Context, resourceGroupName string, computeName string) error {
f, err := s.client.VirtualMachinesClient.PowerOff(ctx, resourceGroupName, computeName) f, err := s.client.VirtualMachinesClient.PowerOff(ctx, resourceGroupName, computeName)
if err == nil { if err == nil {
err = f.WaitForCompletion(ctx, s.client.VirtualMachinesClient.Client) err = f.WaitForCompletion(ctx, s.client.VirtualMachinesClient.Client)
@ -48,11 +47,9 @@ func (s *StepPowerOffCompute) Run(ctx context.Context, state multistep.StateBag)
s.say(fmt.Sprintf(" -> ResourceGroupName : '%s'", resourceGroupName)) s.say(fmt.Sprintf(" -> ResourceGroupName : '%s'", resourceGroupName))
s.say(fmt.Sprintf(" -> ComputeName : '%s'", computeName)) s.say(fmt.Sprintf(" -> ComputeName : '%s'", computeName))
result := common.StartInterruptibleTask( err := s.powerOff(ctx, resourceGroupName, computeName)
func() bool { return common.IsStateCancelled(state) },
func(cancelCh <-chan struct{}) error { return s.powerOff(ctx, resourceGroupName, computeName, cancelCh) })
return processInterruptibleResult(result, s.error, state) return processStepResult(err, s.error, state)
} }
func (*StepPowerOffCompute) Cleanup(multistep.StateBag) { func (*StepPowerOffCompute) Cleanup(multistep.StateBag) {

View File

@ -11,7 +11,7 @@ import (
func TestStepPowerOffComputeShouldFailIfPowerOffFails(t *testing.T) { func TestStepPowerOffComputeShouldFailIfPowerOffFails(t *testing.T) {
var testSubject = &StepPowerOffCompute{ var testSubject = &StepPowerOffCompute{
powerOff: func(string, string, <-chan struct{}) error { return fmt.Errorf("!! Unit Test FAIL !!") }, powerOff: func(context.Context, string, string) error { return fmt.Errorf("!! Unit Test FAIL !!") },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
} }
@ -30,7 +30,7 @@ func TestStepPowerOffComputeShouldFailIfPowerOffFails(t *testing.T) {
func TestStepPowerOffComputeShouldPassIfPowerOffPasses(t *testing.T) { func TestStepPowerOffComputeShouldPassIfPowerOffPasses(t *testing.T) {
var testSubject = &StepPowerOffCompute{ var testSubject = &StepPowerOffCompute{
powerOff: func(string, string, <-chan struct{}) error { return nil }, powerOff: func(context.Context, string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
} }
@ -52,7 +52,7 @@ func TestStepPowerOffComputeShouldTakeStepArgumentsFromStateBag(t *testing.T) {
var actualComputeName string var actualComputeName string
var testSubject = &StepPowerOffCompute{ var testSubject = &StepPowerOffCompute{
powerOff: func(resourceGroupName string, computeName string, cancelCh <-chan struct{}) error { powerOff: func(ctx context.Context, resourceGroupName string, computeName string) error {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualComputeName = computeName actualComputeName = computeName

View File

@ -11,7 +11,7 @@ import (
func TestStepValidateTemplateShouldFailIfValidateFails(t *testing.T) { func TestStepValidateTemplateShouldFailIfValidateFails(t *testing.T) {
var testSubject = &StepValidateTemplate{ var testSubject = &StepValidateTemplate{
validate: func(string, string) error { return fmt.Errorf("!! Unit Test FAIL !!") }, validate: func(context.Context, string, string) error { return fmt.Errorf("!! Unit Test FAIL !!") },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
} }
@ -30,7 +30,7 @@ func TestStepValidateTemplateShouldFailIfValidateFails(t *testing.T) {
func TestStepValidateTemplateShouldPassIfValidatePasses(t *testing.T) { func TestStepValidateTemplateShouldPassIfValidatePasses(t *testing.T) {
var testSubject = &StepValidateTemplate{ var testSubject = &StepValidateTemplate{
validate: func(string, string) error { return nil }, validate: func(context.Context, string, string) error { return nil },
say: func(message string) {}, say: func(message string) {},
error: func(e error) {}, error: func(e error) {},
} }
@ -52,7 +52,7 @@ func TestStepValidateTemplateShouldTakeStepArgumentsFromStateBag(t *testing.T) {
var actualDeploymentName string var actualDeploymentName string
var testSubject = &StepValidateTemplate{ var testSubject = &StepValidateTemplate{
validate: func(resourceGroupName string, deploymentName string) error { validate: func(ctx context.Context, resourceGroupName string, deploymentName string) error {
actualResourceGroupName = resourceGroupName actualResourceGroupName = resourceGroupName
actualDeploymentName = deploymentName actualDeploymentName = deploymentName

View File

@ -140,7 +140,7 @@
}, },
"osDisk": { "osDisk": {
"caching": "ReadWrite", "caching": "ReadWrite",
"createOption": "fromImage", "createOption": "FromImage",
"managedDisk": { "managedDisk": {
"storageAccountType": "Standard_LRS" "storageAccountType": "Standard_LRS"
}, },

View File

@ -143,7 +143,7 @@
}, },
"osDisk": { "osDisk": {
"caching": "ReadWrite", "caching": "ReadWrite",
"createOption": "fromImage", "createOption": "FromImage",
"managedDisk": { "managedDisk": {
"storageAccountType": "Standard_LRS" "storageAccountType": "Standard_LRS"
}, },

View File

@ -121,7 +121,7 @@
}, },
"osDisk": { "osDisk": {
"caching": "ReadWrite", "caching": "ReadWrite",
"createOption": "fromImage", "createOption": "FromImage",
"managedDisk": { "managedDisk": {
"storageAccountType": "Standard_LRS" "storageAccountType": "Standard_LRS"
}, },

View File

@ -155,7 +155,7 @@
}, },
"osDisk": { "osDisk": {
"caching": "ReadWrite", "caching": "ReadWrite",
"createOption": "fromImage", "createOption": "FromImage",
"managedDisk": { "managedDisk": {
"storageAccountType": "Standard_LRS" "storageAccountType": "Standard_LRS"
}, },

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/arm/resources/resources" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources"
"github.com/approvals/go-approval-tests" "github.com/approvals/go-approval-tests"
"github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/common/constants"
"github.com/hashicorp/packer/builder/azure/common/template" "github.com/hashicorp/packer/builder/azure/common/template"

View File

@ -179,7 +179,7 @@
}, },
"osDisk": { "osDisk": {
"caching": "ReadWrite", "caching": "ReadWrite",
"createOption": "fromImage", "createOption": "FromImage",
"managedDisk": { "managedDisk": {
"storageAccountType": "Premium_LRS" "storageAccountType": "Premium_LRS"
}, },

View File

@ -3,7 +3,7 @@ package template
import ( import (
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/approvals/go-approval-tests" "github.com/approvals/go-approval-tests"
) )