@@ -34,27 +34,45 @@ func TestConvertToTemplate(t *testing.T) {
3434 expectCallCreateTemplate bool
3535 createTemplateErr error
3636 expectedAction multistep.StepAction
37- expectTemplateIdSet bool
37+ expectArtifactIdSet bool
38+ expectArtifactType string
39+ builderConfig * Config
3840 }{
3941 {
4042 name : "no errors returns continue and sets template id" ,
4143 expectCallCreateTemplate : true ,
4244 expectedAction : multistep .ActionContinue ,
43- expectTemplateIdSet : true ,
45+ expectArtifactIdSet : true ,
46+ expectArtifactType : "template" ,
47+ builderConfig : & Config {},
48+ },
49+ {
50+ name : "no errors returns continue and sets vm id" ,
51+ expectCallCreateTemplate : true ,
52+ expectedAction : multistep .ActionContinue ,
53+ expectArtifactIdSet : true ,
54+ expectArtifactType : "VM" ,
55+ builderConfig : & Config {
56+ SkipConvertToTemplate : true ,
57+ },
4458 },
4559 {
4660 name : "when shutdown fails, don't try to create template and halt" ,
4761 shutdownErr : fmt .Errorf ("failed to stop vm" ),
4862 expectCallCreateTemplate : false ,
4963 expectedAction : multistep .ActionHalt ,
50- expectTemplateIdSet : false ,
64+ expectArtifactIdSet : false ,
65+ expectArtifactType : "" ,
66+ builderConfig : & Config {},
5167 },
5268 {
5369 name : "when create template fails, halt" ,
5470 expectCallCreateTemplate : true ,
5571 createTemplateErr : fmt .Errorf ("failed to stop vm" ),
5672 expectedAction : multistep .ActionHalt ,
57- expectTemplateIdSet : false ,
73+ expectArtifactIdSet : false ,
74+ expectArtifactType : "" ,
75+ builderConfig : & Config {},
5876 },
5977 }
6078
@@ -85,21 +103,31 @@ func TestConvertToTemplate(t *testing.T) {
85103 state .Put ("ui" , packersdk .TestUi (t ))
86104 state .Put ("vmRef" , proxmox .NewVmRef (vmid ))
87105 state .Put ("proxmoxClient" , converter )
106+ state .Put ("config" , c .builderConfig )
88107
89108 step := stepConvertToTemplate {}
90109 action := step .Run (context .TODO (), state )
91110 if action != c .expectedAction {
92111 t .Errorf ("Expected action to be %v, got %v" , c .expectedAction , action )
93112 }
94113
95- id , wasSet := state .GetOk ("template_id" )
114+ artifactId , artifactIdWasSet := state .GetOk ("artifact_id" )
115+ artifactType , artifactTypeWasSet := state .GetOk ("artifact_type" )
116+
117+ if c .expectArtifactIdSet != artifactIdWasSet {
118+ t .Errorf ("Expected artifact_id state present=%v was present=%v" , c .expectArtifactIdSet , artifactIdWasSet )
119+ }
120+
121+ if c .expectArtifactIdSet && artifactId != vmid {
122+ t .Errorf ("Expected artifact_id state to be set to %d, got %v" , vmid , artifactId )
123+ }
96124
97- if c .expectTemplateIdSet != wasSet {
98- t .Errorf ("Expected template_id state present=%v was present=%v" , c .expectTemplateIdSet , wasSet )
125+ if c .expectArtifactType == "" && artifactTypeWasSet {
126+ t .Errorf ("Expected artifact_type state present=%v was present=%v" , c .expectArtifactType , artifactTypeWasSet )
99127 }
100128
101- if c . expectTemplateIdSet && id != vmid {
102- t .Errorf ("Expected template_id state to be set to %d , got %v " , vmid , id )
129+ if artifactTypeWasSet && c . expectArtifactType != artifactType {
130+ t .Errorf ("Expected artifact_type state to be set to %s , got %s " , c . expectArtifactType , artifactType )
103131 }
104132 })
105133 }
0 commit comments