github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/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 config := new(Config) 34 var testSubject = &StepSetCertificate{ 35 config: config, 36 say: func(message string) {}, 37 error: func(e error) {}, 38 } 39 40 stateBag := createTestStateBagStepSetCertificate() 41 var result = testSubject.Run(stateBag) 42 43 if result != multistep.ActionContinue { 44 t.Fatalf("Expected the step to return 'ActionContinue', but got '%d'.", result) 45 } 46 47 if config.tmpWinRMCertificateUrl != stateBag.Get(constants.ArmCertificateUrl) { 48 t.Fatalf("Expected config.tmpWinRMCertificateUrl to be %s, but got %s'", stateBag.Get(constants.ArmCertificateUrl), config.tmpWinRMCertificateUrl) 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 }