From 66a9cbb7d91f3dcb29c67b3a9526f1039588df37 Mon Sep 17 00:00:00 2001 From: Deluan Date: Thu, 28 Oct 2021 10:40:31 -0400 Subject: [PATCH] Remove temp folders after tests --- core/artwork_test.go | 3 +++ core/media_streamer_test.go | 3 +++ persistence/album_repository_test.go | 30 +++++++++++++++++----------- utils/cache/file_caches_test.go | 2 +- utils/cache/spread_fs_test.go | 3 +-- utils/merge_fs_test.go | 4 ++++ 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/core/artwork_test.go b/core/artwork_test.go index 936bf69b3..5d1c846c6 100644 --- a/core/artwork_test.go +++ b/core/artwork_test.go @@ -39,6 +39,9 @@ var _ = Describe("Artwork", func() { Eventually(func() bool { return cache.Ready(context.TODO()) }).Should(BeTrue()) artwork = NewArtwork(ds, cache) }) + AfterEach(func() { + _ = os.RemoveAll(conf.Server.DataFolder) + }) It("retrieves the external artwork art for an album", func() { r, err := artwork.Get(ctx, "al-444", 0) diff --git a/core/media_streamer_test.go b/core/media_streamer_test.go index 04a663243..37ecc0322 100644 --- a/core/media_streamer_test.go +++ b/core/media_streamer_test.go @@ -32,6 +32,9 @@ var _ = Describe("MediaStreamer", func() { Eventually(func() bool { return testCache.Ready(context.TODO()) }).Should(BeTrue()) streamer = NewMediaStreamer(ds, ffmpeg, testCache) }) + AfterEach(func() { + _ = os.RemoveAll(conf.Server.DataFolder) + }) Context("NewStream", func() { It("returns a seekable stream if format is 'raw'", func() { diff --git a/persistence/album_repository_test.go b/persistence/album_repository_test.go index c05bb104d..3f67282f0 100644 --- a/persistence/album_repository_test.go +++ b/persistence/album_repository_test.go @@ -88,19 +88,25 @@ var _ = Describe("AlbumRepository", func() { }) Describe("getCoverFromPath", func() { - testFolder, _ := os.MkdirTemp("", "album_persistence_tests") - if err := os.MkdirAll(testFolder, 0777); err != nil { - panic(err) - } - if _, err := os.Create(filepath.Join(testFolder, "Cover.jpeg")); err != nil { - panic(err) - } - if _, err := os.Create(filepath.Join(testFolder, "FRONT.PNG")); err != nil { - panic(err) - } + var testFolder, testPath, embeddedPath string + BeforeEach(func() { + testFolder, _ = os.MkdirTemp("", "album_persistence_tests") + if err := os.MkdirAll(testFolder, 0777); err != nil { + panic(err) + } + if _, err := os.Create(filepath.Join(testFolder, "Cover.jpeg")); err != nil { + panic(err) + } + if _, err := os.Create(filepath.Join(testFolder, "FRONT.PNG")); err != nil { + panic(err) + } + testPath = filepath.Join(testFolder, "somefile.test") + embeddedPath = filepath.Join(testFolder, "somefile.mp3") + }) + AfterEach(func() { + _ = os.RemoveAll(testFolder) + }) - testPath := filepath.Join(testFolder, "somefile.test") - embeddedPath := filepath.Join(testFolder, "somefile.mp3") It("returns audio file for embedded cover", func() { conf.Server.CoverArtPriority = "embedded, cover.*, front.*" Expect(getCoverFromPath(testPath, embeddedPath)).To(Equal("")) diff --git a/utils/cache/file_caches_test.go b/utils/cache/file_caches_test.go index f6408e173..de3691231 100644 --- a/utils/cache/file_caches_test.go +++ b/utils/cache/file_caches_test.go @@ -24,7 +24,7 @@ var _ = Describe("File Caches", func() { conf.Server.DataFolder, _ = os.MkdirTemp("", "file_caches") }) AfterEach(func() { - os.RemoveAll(conf.Server.DataFolder) + _ = os.RemoveAll(conf.Server.DataFolder) }) Describe("NewFileCache", func() { diff --git a/utils/cache/spread_fs_test.go b/utils/cache/spread_fs_test.go index cad185deb..ac4039866 100644 --- a/utils/cache/spread_fs_test.go +++ b/utils/cache/spread_fs_test.go @@ -19,9 +19,8 @@ var _ = Describe("Spread FS", func() { fs, err = NewSpreadFS(rootDir, 0755) Expect(err).To(BeNil()) }) - AfterEach(func() { - Expect(os.RemoveAll(rootDir)).To(BeNil()) + _ = os.RemoveAll(rootDir) }) Describe("KeyMapper", func() { diff --git a/utils/merge_fs_test.go b/utils/merge_fs_test.go index 7aab37bd9..a02aeba47 100644 --- a/utils/merge_fs_test.go +++ b/utils/merge_fs_test.go @@ -22,6 +22,10 @@ var _ = Describe("MergeFS", func() { overlayDir = os.DirFS(overlayName) mergedDir = utils.MergeFS{Base: baseDir, Overlay: overlayDir} }) + AfterEach(func() { + _ = os.RemoveAll(baseName) + _ = os.RemoveAll(overlayName) + }) It("reads from Base dir if not found in Overlay", func() { _f(baseName, "a.json")