Skip to content

Commit

Permalink
Revert to maual cleanup for some tests
Browse files Browse the repository at this point in the history
- cleanup of these directories fails on Windows
- manual cleanup `err`'s can be intentionally ignored
- using `GinkgoT().TempDir()` automatically cleans up but errors can not
  be ignored
  • Loading branch information
aramprice committed Jul 22, 2024
1 parent dde25b5 commit 2cafb3b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
19 changes: 17 additions & 2 deletions package_stemcell/packagers/packager_utility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ var _ = Describe("Packager Utility", func() {
var destinationDir string

BeforeEach(func() {
sourceDir = GinkgoT().TempDir() // automatically cleaned up
destinationDir = GinkgoT().TempDir() // automatically cleaned up
// Revert to manual cleanup which fails non-catastrophically on windows
//sourceDir = GinkgoT().TempDir() // automatically cleaned up
//destinationDir = GinkgoT().TempDir() // automatically cleaned up
sourceDir, _ = os.MkdirTemp(os.TempDir(), "packager-utility-test-source")
destinationDir, _ = os.MkdirTemp(os.TempDir(), "packager-utility-test-destination")
})

AfterEach(func() {
// TODO: remove once GinkgoT().TempDir() is safe on windows
err := os.RemoveAll(sourceDir)
if err != nil {
By(fmt.Sprintf("removing '%s' failed: %s", sourceDir, err))
}
err = os.RemoveAll(destinationDir)
if err != nil {
By(fmt.Sprintf("removing '%s' failed: %s", destinationDir, err))
}
})

It("should tar all files inside provided folder and return its sha1", func() {
Expand Down
13 changes: 12 additions & 1 deletion package_stemcell/packagers/vcenter_packager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ var _ = Describe("VcenterPackager", func() {
var fakeVcenterClient *packagersfakes.FakeIaasClient

BeforeEach(func() {
outputDir = GinkgoT().TempDir() // automatically cleaned up
// Revert to manual cleanup which fails non-catastrophically on windows
//outputDir = GinkgoT().TempDir() // automatically cleaned up
outputDir, _ = os.MkdirTemp(os.TempDir(), "vcenter-test-output-dir")

sourceConfig = config.SourceConfig{Password: "password", URL: "url", Username: "username", VmInventoryPath: "path/valid-vm-name"}
outputConfig = config.OutputConfig{Os: "2012R2", StemcellVersion: "1200.2", OutputDir: outputDir}
fakeVcenterClient = &packagersfakes.FakeIaasClient{}
})

AfterEach(func() {
// TODO: remove once GinkgoT().TempDir() is safe on windows
err := os.RemoveAll(outputDir)
if err != nil {
By(fmt.Sprintf("removing '%s' failed: %s", outputDir, err))
}
})

Context("ValidateSourceParameters", func() {
It("returns an error if the vCenter url is invalid", func() {
fakeVcenterClient.ValidateUrlReturns(errors.New("vcenter client url error"))
Expand Down
12 changes: 11 additions & 1 deletion package_stemcell/stemcell_generator/tar/tar_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"compress/gzip"
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand All @@ -29,7 +30,10 @@ var _ = Describe("TarWriter", func() {
originalWorkingDir, err = os.Getwd()
Expect(err).NotTo(HaveOccurred())

workingDir = GinkgoT().TempDir() // automatically cleaned up
// Revert to manual cleanup which fails non-catastrophically on windows
//workingDir = GinkgoT().TempDir() // automatically cleaned up
workingDir, err = os.MkdirTemp(os.TempDir(), "TarWriterTest")
Expect(err).NotTo(HaveOccurred())

fakeFile := bytes.NewReader([]byte{})
fakeTarable = &tarfakes.FakeTarable{}
Expand All @@ -40,6 +44,12 @@ var _ = Describe("TarWriter", func() {

AfterEach(func() {
Expect(os.Chdir(originalWorkingDir)).To(Succeed())

// TODO: remove once GinkgoT().TempDir() is safe on windows
err := os.RemoveAll(workingDir)
if err != nil {
By(fmt.Sprintf("removing '%s' failed: %s", workingDir, err))
}
})

It("should not fail", func() {
Expand Down

0 comments on commit 2cafb3b

Please sign in to comment.