Skip to content

Commit 01c4289

Browse files
committed
stembuild: cleanup vmconstruct_test
Fixes spacing and variable scoping
1 parent 06ea578 commit 01c4289

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

stembuild/construct/vmconstruct_test.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var _ = Describe("construct_helpers", func() {
3232
fakeScriptExecutor *constructfakes.FakeScriptExecutorI
3333
fakeSetupFlags []string
3434
)
35-
const rawLogoffCommand = `&{If([string]::IsNullOrEmpty($(Get-WmiObject win32_computersystem).username)) {Write-Host "No users logged in." } Else {Write-Host "Logging out user."; $(Get-WmiObject win32_operatingsystem).Win32Shutdown(0) 1> $null}}`
35+
3636
BeforeEach(func() {
3737
fakeRemoteManager = &remotemanagerfakes.FakeRemoteManager{}
3838
fakeVcenterClient = &constructfakes.FakeIaasClient{}
@@ -73,12 +73,10 @@ var _ = Describe("construct_helpers", func() {
7373

7474
fakeGuestManager.DownloadFileInGuestReturns(versionBuffer, 3, nil)
7575
fakeGuestManager.StartProgramInGuestReturns(0, nil)
76-
7776
})
7877

7978
Describe("ScriptExecutor", func() {
8079
It("executes setup script with correct arguments", func() {
81-
8280
e := construct.NewScriptExecutor(fakeRemoteManager)
8381
version := "11.11.11"
8482
err := e.ExecuteSetupScript(version, fakeSetupFlags)
@@ -128,7 +126,6 @@ var _ = Describe("construct_helpers", func() {
128126
Expect(err).To(HaveOccurred())
129127
Expect(err.Error()).To(ContainSubstring("winrm connection event"))
130128
})
131-
132129
})
133130

134131
Describe("PrepareVM", func() {
@@ -178,7 +175,6 @@ var _ = Describe("construct_helpers", func() {
178175
})
179176

180177
Describe("connect to VM", func() {
181-
182178
It("checks for WinRM connectivity after WinRM enabled", func() {
183179
var calls []string
184180

@@ -233,7 +229,6 @@ var _ = Describe("construct_helpers", func() {
233229

234230
Expect(fakeMessenger.UploadFileSucceededCallCount()).To(Equal(2))
235231
})
236-
237232
})
238233

239234
Context("Fails to upload one or more artifacts", func() {
@@ -255,7 +250,6 @@ var _ = Describe("construct_helpers", func() {
255250
})
256251

257252
It("fails when it cannot upload Stemcell Automation scripts", func() {
258-
259253
uploadError := errors.New("failed to upload stemcell automation")
260254
fakeVcenterClient.UploadArtifactReturnsOnCall(0, nil)
261255
fakeVcenterClient.UploadArtifactReturnsOnCall(1, uploadError)
@@ -278,6 +272,8 @@ var _ = Describe("construct_helpers", func() {
278272
})
279273

280274
Describe("logs out users", func() {
275+
var rawLogoffCommand = `&{If([string]::IsNullOrEmpty($(Get-WmiObject win32_computersystem).username)) {Write-Host "No users logged in." } Else {Write-Host "Logging out user."; $(Get-WmiObject win32_operatingsystem).Win32Shutdown(0) 1> $null}}`
276+
281277
It("returns success when active user is logged out", func() {
282278
fakeRemoteManager.ExecuteCommandReturnsOnCall(0, 0, nil)
283279

@@ -292,8 +288,9 @@ var _ = Describe("construct_helpers", func() {
292288
Expect(fakeMessenger.LogOutUsersStartedCallCount()).To(Equal(1))
293289
Expect(fakeMessenger.LogOutUsersSucceededCallCount()).To(Equal(1))
294290
})
291+
295292
It("returns failure when it fails to execute a logout", func() {
296-
errorMessage := "Unable to execute command"
293+
errorMessage := "unable to execute command"
297294
fakeRemoteManager.ExecuteCommandReturnsOnCall(0, 1, errors.New(errorMessage))
298295

299296
err := vmConstruct.PrepareVM()
@@ -332,7 +329,6 @@ var _ = Describe("construct_helpers", func() {
332329
Expect(fakeMessenger.ExtractArtifactsStartedCallCount()).To(Equal(1))
333330
Expect(fakeMessenger.ExtractArtifactsSucceededCallCount()).To(Equal(1))
334331
})
335-
336332
})
337333

338334
Describe("can execute setup scripts", func() {
@@ -365,8 +361,8 @@ var _ = Describe("construct_helpers", func() {
365361
Expect(fakeMessenger.ExecuteSetupScriptStartedCallCount()).To(Equal(1))
366362
Expect(fakeMessenger.ExecuteSetupScriptSucceededCallCount()).To(Equal(1))
367363
})
368-
369364
})
365+
370366
Describe("can check if vm is rebooting", func() {
371367
It("waits for reboot finished after the setup script has been executed", func() {
372368
var calls []string
@@ -444,7 +440,6 @@ var _ = Describe("construct_helpers", func() {
444440
})
445441

446442
It("runs post-reboot command", func() {
447-
448443
err := vmConstruct.PrepareVM()
449444

450445
Expect(err).NotTo(HaveOccurred())
@@ -463,8 +458,8 @@ var _ = Describe("construct_helpers", func() {
463458
Expect(err.Error()).To(ContainSubstring(postRebootError.Error()))
464459
Expect(fakeMessenger.ExecutePostRebootScriptStartedCallCount()).To(Equal(1))
465460
Expect(fakeMessenger.ExecutePostRebootScriptSucceededCallCount()).To(Equal(0))
466-
467461
})
462+
468463
It("logs but does not error on winrm, non-powershell errors", func() {
469464
winrmError := errors.New("winrm connection event: some EOF error")
470465

@@ -480,7 +475,6 @@ var _ = Describe("construct_helpers", func() {
480475
Expect(fakeMessenger.ExecutePostRebootWarningArgsForCall(0)).
481476
To(ContainSubstring(winrmError.Error()))
482477
})
483-
484478
})
485479

486480
Describe("can check that the VM is powered off", func() {

0 commit comments

Comments
 (0)