github.com/mitchellh/packer@v1.3.2/builder/azure/arm/step_set_certificate_test.go (about)

     1  package arm
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/packer/builder/azure/common/constants"
     8  	"github.com/hashicorp/packer/helper/multistep"
     9  )
    10  
    11  func TestStepSetCertificateShouldPassIfGetPasses(t *testing.T) {
    12  	var testSubject = &StepSetCertificate{
    13  		config: new(Config),
    14  		say:    func(message string) {},
    15  		error:  func(e error) {},
    16  	}
    17  
    18  	stateBag := createTestStateBagStepSetCertificate()
    19  
    20  	var result = testSubject.Run(context.Background(), stateBag)
    21  	if result != multistep.ActionContinue {
    22  		t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result)
    23  	}
    24  
    25  	if _, ok := stateBag.GetOk(constants.Error); ok == true {
    26  		t.Fatalf("Expected the step to not set stateBag['%s'], but it was.", constants.Error)
    27  	}
    28  }
    29  
    30  func TestStepSetCertificateShouldTakeStepArgumentsFromStateBag(t *testing.T) {
    31  	config := new(Config)
    32  	var testSubject = &StepSetCertificate{
    33  		config: config,
    34  		say:    func(message string) {},
    35  		error:  func(e error) {},
    36  	}
    37  
    38  	stateBag := createTestStateBagStepSetCertificate()
    39  	var result = testSubject.Run(context.Background(), stateBag)
    40  
    41  	if result != multistep.ActionContinue {
    42  		t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result)
    43  	}
    44  
    45  	if config.tmpWinRMCertificateUrl != stateBag.Get(constants.ArmCertificateUrl) {
    46  		t.Fatalf("Expected config.tmpWinRMCertificateUrl to be %s, but got %s'", stateBag.Get(constants.ArmCertificateUrl), config.tmpWinRMCertificateUrl)
    47  	}
    48  }
    49  
    50  func createTestStateBagStepSetCertificate() multistep.StateBag {
    51  	stateBag := new(multistep.BasicStateBag)
    52  	stateBag.Put(constants.ArmCertificateUrl, "Unit Test: Certificate URL")
    53  	return stateBag
    54  }