github.com/cloudfoundry-incubator/stembuild@v0.0.0-20211223202937-5b61d62226c6/integration/construct/winrm_test.go (about) 1 package construct_test 2 3 import ( 4 "path/filepath" 5 6 . "github.com/cloudfoundry-incubator/stembuild/remotemanager" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("WinRM Remote Manager", func() { 12 13 var rm RemoteManager 14 15 BeforeEach(func() { 16 clientFactory := NewWinRmClientFactory(conf.TargetIP, conf.VMUsername, conf.VMPassword) 17 rm = NewWinRM(conf.TargetIP, conf.VMUsername, conf.VMPassword, clientFactory) 18 Expect(rm).ToNot(BeNil()) 19 }) 20 21 AfterEach(func() { 22 _, err := rm.ExecuteCommand("powershell.exe Remove-Item c:\\provision -recurse") 23 Expect(err).ToNot(HaveOccurred()) 24 }) 25 26 Context("ExtractArchive", func() { 27 BeforeEach(func() { 28 err := rm.UploadArtifact(filepath.Join("assets", "StemcellAutomation.zip"), "C:\\provision\\StemcellAutomation.zip") 29 Expect(err).ToNot(HaveOccurred()) 30 }) 31 32 It("succeeds when Extract-Archive powershell function returns zero exit code", func() { 33 err := rm.ExtractArchive("C:\\provision\\StemcellAutomation.zip", "C:\\provision") 34 Expect(err).ToNot(HaveOccurred()) 35 }) 36 37 It("fails when Extract-Archive powershell function returns non-zero exit code", func() { 38 err := rm.ExtractArchive("C:\\provision\\NonExistingFile.zip", "C:\\provision") 39 Expect(err).To(HaveOccurred()) 40 Expect(err.Error()).To(HavePrefix("powershell encountered an issue: ")) 41 }) 42 }) 43 44 Context("ExecuteCommand", func() { 45 It("succeeds when powershell command returns a zero exit code", func() { 46 _, err := rm.ExecuteCommand("powershell.exe \"ls c:\\windows 1>$null\"") 47 Expect(err).ToNot(HaveOccurred()) 48 }) 49 50 It("fails when powershell command returns non-zero exit code", func() { 51 _, err := rm.ExecuteCommand("powershell.exe notRealCommand") 52 Expect(err).To(HaveOccurred()) 53 Expect(err.Error()).To(HavePrefix("powershell encountered an issue: ")) 54 }) 55 }) 56 })