Skip to content

Commit 7ffa1b1

Browse files
committed
Add unit tests
1 parent a0c9e44 commit 7ffa1b1

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

builder/googlecompute/step_create_image_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,47 @@ func TestStepCreateImage_setsDeprecationFields(t *testing.T) {
9393
assert.Equal(t, c.DeleteAt, d.DeprecatedImageStatus.Deleted, "DeleteAt mismatch")
9494
assert.Contains(t, []string{"DEPRECATED", "ACTIVE"}, d.DeprecatedImageStatus.State, "State should be DEPRECATED or ACTIVE")
9595
}
96+
97+
func TestStepCreateImageNonUEFI_image(t *testing.T) {
98+
state := testState(t)
99+
step := new(StepCreateImage)
100+
defer step.Cleanup(state)
101+
102+
c := state.Get("config").(*Config)
103+
c.ImageGuestOsFeatures = []string{}
104+
105+
// run the step
106+
action := step.Run(context.Background(), state)
107+
assert.Equal(t, action, multistep.ActionContinue, "Step did not pass.")
108+
109+
uncastImage, ok := state.GetOk("image")
110+
assert.True(t, ok, "State does not have resulting image.")
111+
image, ok := uncastImage.(*common.Image)
112+
assert.True(t, ok, "Image in state is not an Image.")
113+
114+
assert.Len(t, image.ShieldedInstanceInitialState.Keks, 1)
115+
assert.Len(t, image.ShieldedInstanceInitialState.Dbs, 1)
116+
assert.Len(t, image.ShieldedInstanceInitialState.Dbxs, 1)
117+
}
118+
119+
func TestStepCreateImageUEFI_image(t *testing.T) {
120+
state := testState(t)
121+
step := new(StepCreateImage)
122+
defer step.Cleanup(state)
123+
124+
c := state.Get("config").(*Config)
125+
c.ImageGuestOsFeatures = []string{"UEFI_COMPATIBLE"}
126+
127+
// run the step
128+
action := step.Run(context.Background(), state)
129+
assert.Equal(t, action, multistep.ActionContinue, "Step did not pass.")
130+
131+
uncastImage, ok := state.GetOk("image")
132+
assert.True(t, ok, "State does not have resulting image.")
133+
image, ok := uncastImage.(*common.Image)
134+
assert.True(t, ok, "Image in state is not an Image.")
135+
136+
assert.Len(t, image.ShieldedInstanceInitialState.Keks, 1)
137+
assert.Len(t, image.ShieldedInstanceInitialState.Dbs, 1)
138+
assert.Len(t, image.ShieldedInstanceInitialState.Dbxs, 1)
139+
}

0 commit comments

Comments
 (0)