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