github.com/yoctocloud/packer@v0.6.2-0.20160520224004-e11a0a18423f/builder/azure/arm/step_set_certificate_test.go (about)

     1  // Copyright (c) Microsoft Corporation. All rights reserved.
     2  // Licensed under the MIT License. See the LICENSE file in builder/azure for license information.
     3  
     4  package arm
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/mitchellh/multistep"
    10  	"github.com/mitchellh/packer/builder/azure/common/constants"
    11  )
    12  
    13  func TestStepSetCertificateShouldPassIfGetPasses(t *testing.T) {
    14  	var testSubject = &StepSetCertificate{
    15  		config: new(Config),
    16  		say:    func(message string) {},
    17  		error:  func(e error) {},
    18  	}
    19  
    20  	stateBag := createTestStateBagStepSetCertificate()
    21  
    22  	var result = testSubject.Run(stateBag)
    23  	if result != multistep.ActionContinue {
    24  		t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result)
    25  	}
    26  
    27  	if _, ok := stateBag.GetOk(constants.Error); ok == true {
    28  		t.Fatalf("Expected the step to not set stateBag['%s'], but it was.", constants.Error)
    29  	}
    30  }
    31  
    32  func TestStepSetCertificateShouldTakeStepArgumentsFromStateBag(t *testing.T) {
    33  	var testSubject = &StepSetCertificate{
    34  		config: new(Config),
    35  		say:    func(message string) {},
    36  		error:  func(e error) {},
    37  	}
    38  
    39  	stateBag := createTestStateBagStepSetCertificate()
    40  	var result = testSubject.Run(stateBag)
    41  
    42  	if result != multistep.ActionContinue {
    43  		t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result)
    44  	}
    45  
    46  	_, ok := stateBag.GetOk(constants.ArmTemplateParameters)
    47  	if !ok {
    48  		t.Fatalf("Expected the state bag to have a value for '%s', but it did not.", constants.ArmTemplateParameters)
    49  	}
    50  }
    51  
    52  func createTestStateBagStepSetCertificate() multistep.StateBag {
    53  	stateBag := new(multistep.BasicStateBag)
    54  	stateBag.Put(constants.ArmCertificateUrl, "Unit Test: Certificate URL")
    55  	return stateBag
    56  }