From 2e7e24a02342064ea1c8e367b56f808688dd4ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deluan=20Quint=C3=A3o?= Date: Sun, 15 Nov 2026 19:07:43 -0500 Subject: [PATCH] chore(lint): ban panic (#6478) * chore(lint): ban panic in production code Add a forbidigo rule that rejects panic outside tests and test helpers (_test.go, tests/ and storagetest/). Its message says to return an error, and to use log.Fatal only for startup failures. The existing production panics are gone: - model.MustParseArtworkID was only used by core/artwork tests. It is now a Gomega helper in those test suites, and it also panicked with the parsed ID instead of the error. - isDBInitialized in db/migrations panicked on a query error and never closed its rows. It now uses QueryRowContext and logs the error. The two http.ErrAbortHandler panics in the stream and API v1 handlers stay, because net/http requires them to abort a response. They are marked with //nolint:forbidigo. cmd/wire_injectors.go is not linted, because of its wireinject build tag. * chore(lint): ban panic in tests too The panic ban excluded test files and test helpers, so agents could read it as permission to panic in tests. The rule now applies everywhere, and its message says what to use instead: return an error, or Expect(...)/Fail(...) in tests. Test panics are replaced with Gomega assertions, and the helpers that assert call GinkgoHelper() so failures point at the calling spec. The fake HTTP clients in the deezer tests and getDirEntry use Fail(...). storagetest.FakeFS.UpdateTags now asserts with Gomega instead of panicking. Seven test panics stay, marked //nolint:forbidigo: they exercise panic recovery or stand in for log.Fatal. * refactor(tests): share panicking test helpers Move mustParseArtworkID out of the two core/artwork suites into tests.MustParseArtworkID, and add conf.PanicOnLogFatal so the conf specs share one panicking logFatal stub and one //nolint. The MustPath spec now asserts the fatal message instead of capturing it. Also merge the back-to-back user and artist loops in the persistence suite setup. --- .golangci.yml | 2 + adapters/deezer/client_auth_test.go | 9 +-- adapters/deezer/client_test.go | 3 +- adapters/deezer/deezer_test.go | 3 +- conf/configuration_test.go | 5 +- conf/dir_test.go | 10 +-- conf/export_test.go | 9 +++ core/artwork/animation_test.go | 12 +-- core/artwork/artwork_test.go | 42 +++++----- core/artwork/e2e/acquire_serve_test.go | 22 +++--- core/artwork/e2e/resolution_harness_test.go | 15 ++-- core/artwork/worker_test.go | 2 +- core/playback/mpv/mpv_test.go | 7 +- core/storage/storagetest/fake_storage.go | 12 ++- core/stream/media_streamer.go | 2 +- db/migrations/migration.go | 24 ++---- model/artwork_id.go | 8 -- model/criteria/criteria_test.go | 4 +- persistence/persistence_suite_test.go | 88 +++++---------------- persistence/playqueue_repository_test.go | 5 +- persistence/radio_repository_test.go | 5 +- scanner/walk_dir_tree_test.go | 4 +- server/apiv1/api.go | 2 +- server/apiv1/api_test.go | 2 +- server/jellyfin/lyrics_test.go | 2 +- server/serve_index_test.go | 10 +-- server/subsonic/e2e/e2e_suite_test.go | 5 +- server/subsonic/middlewares_test.go | 13 +-- server/throttle_backlog_test.go | 2 +- tests/test_helpers.go | 9 +++ utils/cache/simple_cache_test.go | 2 +- utils/merge/merge_fs_test.go | 5 +- 32 files changed, 128 insertions(+), 217 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 95ce5d685..c984ee488 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -143,6 +143,8 @@ linters: msg: "use tx.QueryRowContext(ctx, ...) in migrations to propagate context" - pattern: '^context\.(Background|TODO)$' msg: "in tests use the spec's ctx (from GinkgoT().Context()), t.Context() or b.Context()" + - pattern: '^panic$' + msg: "don't panic: return an error, or Expect(...)/Fail(...) in tests; log.Fatal only for startup failures that must stop the server" nolintlint: require-specific: true allow-unused: false diff --git a/adapters/deezer/client_auth_test.go b/adapters/deezer/client_auth_test.go index dd2acc9fa..0555d2f8e 100644 --- a/adapters/deezer/client_auth_test.go +++ b/adapters/deezer/client_auth_test.go @@ -280,15 +280,12 @@ var _ = Describe("JWT Authentication", func() { // createTestJWT creates a valid JWT token for testing purposes func createTestJWT(expiresIn time.Duration) string { + GinkgoHelper() token, err := jwt.NewBuilder(). Expiration(time.Now().Add(expiresIn)). Build() - if err != nil { - panic(fmt.Sprintf("failed to create test JWT: %v", err)) - } + Expect(err).ToNot(HaveOccurred()) signed, err := jwt.Sign(token, jwt.WithInsecureNoSignature()) - if err != nil { - panic(fmt.Sprintf("failed to sign test JWT: %v", err)) - } + Expect(err).ToNot(HaveOccurred()) return string(signed) } diff --git a/adapters/deezer/client_test.go b/adapters/deezer/client_test.go index 84d981a76..d21c61da3 100644 --- a/adapters/deezer/client_test.go +++ b/adapters/deezer/client_test.go @@ -238,5 +238,6 @@ func (c *fakeHttpClient) Do(req *http.Request) (*http.Response, error) { if resp, ok := c.responses[u.String()]; ok { return resp, nil } - panic("URL not mocked: " + u.String()) + Fail("URL not mocked: " + u.String()) + return nil, nil } diff --git a/adapters/deezer/deezer_test.go b/adapters/deezer/deezer_test.go index 14af2ac4a..c0dd3617a 100644 --- a/adapters/deezer/deezer_test.go +++ b/adapters/deezer/deezer_test.go @@ -290,5 +290,6 @@ func (c *langAwareHttpClient) Do(req *http.Request) (*http.Response, error) { }, nil } - panic("URL not mocked: " + req.URL.String()) + Fail("URL not mocked: " + req.URL.String()) + return nil, nil } diff --git a/conf/configuration_test.go b/conf/configuration_test.go index efd1554fb..a52628e3b 100644 --- a/conf/configuration_test.go +++ b/conf/configuration_test.go @@ -34,10 +34,7 @@ var _ = Describe("Configuration", func() { viper.SetDefault("loglevel", "error") conf.ResetConf() - // Panic instead of exiting on fatal errors to allow testing error conditions - DeferCleanup(conf.SetLogFatal(func(args ...any) { - panic(fmt.Sprint(args...)) - })) + DeferCleanup(conf.PanicOnLogFatal()) }) Describe("ParseLanguages", func() { diff --git a/conf/dir_test.go b/conf/dir_test.go index 79db379d2..daedc5da8 100644 --- a/conf/dir_test.go +++ b/conf/dir_test.go @@ -82,20 +82,14 @@ var _ = Describe("Dir", func() { }) It("calls logFatal on error", func() { - var fatalMsg []any - restore := conf.SetLogFatal(func(args ...any) { - fatalMsg = args - panic("logFatal called") - }) - DeferCleanup(restore) + DeferCleanup(conf.PanicOnLogFatal()) f := GinkgoT().TempDir() + "/blocker" Expect(os.WriteFile(f, []byte("x"), 0600)).To(Succeed()) invalid := f + "/subdir" d := conf.NewDir(invalid) - Expect(func() { d.MustPath() }).To(Panic()) - Expect(fatalMsg).ToNot(BeEmpty()) + Expect(func() { d.MustPath() }).To(PanicWith(ContainSubstring("creating directory"))) }) }) diff --git a/conf/export_test.go b/conf/export_test.go index dbea63cb5..e0aa683cd 100644 --- a/conf/export_test.go +++ b/conf/export_test.go @@ -1,5 +1,7 @@ package conf +import "fmt" + func ResetConf() { current.Store(&Options{}) } @@ -33,6 +35,13 @@ func SetLogFatal(f func(...any)) func() { return func() { logFatal = old } } +// PanicOnLogFatal stops the caller the way os.Exit would, so specs can assert on the fatal message. +func PanicOnLogFatal() func() { + return SetLogFatal(func(args ...any) { + panic(fmt.Sprint(args...)) //nolint:forbidigo + }) +} + var UnknownConfigKeys = unknownConfigKeys var SuggestOptions = suggestOptions diff --git a/core/artwork/animation_test.go b/core/artwork/animation_test.go index 9000a8511..c7128de60 100644 --- a/core/artwork/animation_test.go +++ b/core/artwork/animation_test.go @@ -65,6 +65,7 @@ var _ = Describe("Animation detection", func() { // createAnimatedGIF creates a minimal animated GIF with the given number of frames. func createAnimatedGIF(frames int) []byte { + GinkgoHelper() g := &gif.GIF{ LoopCount: 0, } @@ -74,10 +75,7 @@ func createAnimatedGIF(frames int) []byte { g.Delay = append(g.Delay, 10) } var buf bytes.Buffer - err := gif.EncodeAll(&buf, g) - if err != nil { - panic(err) - } + Expect(gif.EncodeAll(&buf, g)).To(Succeed()) return buf.Bytes() } @@ -151,11 +149,9 @@ func createAPNGBytes() []byte { // createStaticPNGBytes creates a minimal valid static PNG. func createStaticPNGBytes() []byte { + GinkgoHelper() img := image.NewRGBA(image.Rect(0, 0, 2, 2)) var buf bytes.Buffer - err := png.Encode(&buf, img) - if err != nil { - panic(err) - } + Expect(png.Encode(&buf, img)).To(Succeed()) return buf.Bytes() } diff --git a/core/artwork/artwork_test.go b/core/artwork/artwork_test.go index a92d52de5..ec8cf8e29 100644 --- a/core/artwork/artwork_test.go +++ b/core/artwork/artwork_test.go @@ -114,7 +114,7 @@ var _ = Describe("Artwork", func() { It("serves a store-backed found image sized (cache miss resizes, second call is a cache hit)", func() { seedFoundStore("al", "al1", coverBytes) - img, err := svc.Get(ctx, model.MustParseArtworkID("al-al1"), 100, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("al-al1"), 100, false) Expect(err).ToNot(HaveOccurred()) // A resized response versions its ETag with the encode settings, not the pixel hash. Expect(img.ETag).To(Equal(representationTag(img.Hash, 100, false))) @@ -128,7 +128,7 @@ var _ = Describe("Artwork", func() { hash, _ := hashImage(bytes.NewReader(coverBytes)) Expect(os.Remove(store.path(hash, "image/jpeg"))).To(Succeed()) Eventually(func(g Gomega) { - img2, err := svc.Get(ctx, model.MustParseArtworkID("al-al1"), 100, false) + img2, err := svc.Get(ctx, tests.MustParseArtworkID("al-al1"), 100, false) g.Expect(err).ToNot(HaveOccurred()) g.Expect(readAll(img2)).To(Equal(resized)) }).Should(Succeed()) @@ -137,7 +137,7 @@ var _ = Describe("Artwork", func() { It("treats a negative size as a full-size request, not a giant resize", func() { seedFoundStore("al", "alneg", coverBytes) - img, err := svc.Get(ctx, model.MustParseArtworkID("al-alneg"), -2000000000, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("al-alneg"), -2000000000, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(coverBytes), "original bytes, no resize (would OOM)") }) @@ -154,7 +154,7 @@ var _ = Describe("Artwork", func() { Source: "folder", SourcePath: imgPath, RefMtime: mtime, })).To(Succeed()) - img, err := svc.Get(ctx, model.MustParseArtworkID("al-al2"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("al-al2"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(coverBytes)) }) @@ -170,7 +170,7 @@ var _ = Describe("Artwork", func() { Source: "folder", SourcePath: secretPath, RefMtime: fileMtime(secretPath), })).To(Succeed()) - _, err := svc.Get(ctx, model.MustParseArtworkID("al-alni"), 0, false) + _, err := svc.Get(ctx, tests.MustParseArtworkID("al-alni"), 0, false) Expect(err).To(MatchError(ErrUnavailable)) Expect(queueRepo.Data[primaryKey("al", "alni")].Priority).To(Equal(model.ArtworkPriorityScan)) }) @@ -201,7 +201,7 @@ var _ = Describe("Artwork", func() { _ = s.Close() }).Should(Succeed()) - _, err = svc.Get(ctx, model.MustParseArtworkID("al-alnic"), 100, false) + _, err = svc.Get(ctx, tests.MustParseArtworkID("al-alnic"), 100, false) Expect(err).To(MatchError(ErrUnavailable)) Expect(queueRepo.Data[primaryKey("al", "alnic")].Priority).To(Equal(model.ArtworkPriorityScan)) }) @@ -217,7 +217,7 @@ var _ = Describe("Artwork", func() { Source: "folder", SourcePath: imgPath, RefMtime: fileMtime(imgPath) + 999, })).To(Succeed()) - _, err := svc.Get(ctx, model.MustParseArtworkID("al-al3"), 0, false) + _, err := svc.Get(ctx, tests.MustParseArtworkID("al-al3"), 0, false) Expect(err).To(MatchError(ErrUnavailable)) Expect(queueRepo.Data[primaryKey("al", "al3")].Priority).To(Equal(model.ArtworkPriorityScan)) ia, err := artRepo.GetItemArtwork(ctx, model.KindAlbumArtwork, "al3", model.ImageTypePrimary) @@ -236,7 +236,7 @@ var _ = Describe("Artwork", func() { Source: "folder", SourcePath: imgPath, RefMtime: fileMtime(imgPath) + 999, })).To(Succeed()) - _, err := svc.Get(ctx, model.MustParseArtworkID("al-al3b"), 100, false) + _, err := svc.Get(ctx, tests.MustParseArtworkID("al-al3b"), 100, false) Expect(err).To(MatchError(ErrUnavailable)) Expect(queueRepo.Data[primaryKey("al", "al3b")].Priority).To(Equal(model.ArtworkPriorityScan)) }) @@ -247,7 +247,7 @@ var _ = Describe("Artwork", func() { Expect(hash).ToNot(BeEmpty()) albumRepo.SetData(model.Albums{}) // the album is deleted; its artwork row survives - _, err := svc.Get(ctx, model.MustParseArtworkID("al-alzz"), 0, false) + _, err := svc.Get(ctx, tests.MustParseArtworkID("al-alzz"), 0, false) Expect(err).To(MatchError(ErrUnavailable)) }) @@ -256,7 +256,7 @@ var _ = Describe("Artwork", func() { ItemKind: "al", ItemID: "al4", AttemptedAt: time.Now().Add(-365 * 24 * time.Hour), })).To(Succeed()) - _, err := svc.Get(ctx, model.MustParseArtworkID("al-al4"), 0, false) + _, err := svc.Get(ctx, tests.MustParseArtworkID("al-al4"), 0, false) Expect(err).To(MatchError(ErrUnavailable)) Expect(queueRepo.Data).To(BeEmpty()) }) @@ -267,7 +267,7 @@ var _ = Describe("Artwork", func() { folderRepo.result = []model.Folder{{Path: "tests/fixtures/artist/an-album", ImageFiles: []string{"cover.jpg"}}} albumRepo.SetData(model.Albums{{ID: "al5", Name: "Album", FolderIDs: []string{"f1"}}}) - img, err := svc.Get(ctx, model.MustParseArtworkID("al-al5"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("al-al5"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(coverBytes)) @@ -280,7 +280,7 @@ var _ = Describe("Artwork", func() { folderRepo.result = nil albumRepo.SetData(model.Albums{{ID: "al6", Name: "Album"}}) - _, err := svc.Get(ctx, model.MustParseArtworkID("al-al6"), 0, false) + _, err := svc.Get(ctx, tests.MustParseArtworkID("al-al6"), 0, false) Expect(err).To(MatchError(ErrUnavailable)) Expect(queueRepo.Data[primaryKey("al", "al6")].Priority).To(Equal(model.ArtworkPriorityBump)) _, err = artRepo.GetItemArtwork(ctx, model.KindAlbumArtwork, "al6", model.ImageTypePrimary) @@ -292,7 +292,7 @@ var _ = Describe("Artwork", func() { It("serves a track's own found art", func() { seedFoundStore("mf", "mf1", coverBytes) - img, err := svc.Get(ctx, model.MustParseArtworkID("mf-mf1"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mf1"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(coverBytes)) }) @@ -303,7 +303,7 @@ var _ = Describe("Artwork", func() { seedFoundStore("al", "albz", coverBytes) mfRepo.SetData(model.MediaFiles{{ID: "mf7", AlbumID: "albz"}}) - img, err := svc.Get(ctx, model.MustParseArtworkID("mf-mf7"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mf7"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(coverBytes), "album art, not the persisted embedded art") }) @@ -313,7 +313,7 @@ var _ = Describe("Artwork", func() { Expect(artRepo.PutItemArtwork(ctx, &model.ItemArtwork{ItemKind: "mf", ItemID: "mf2"})).To(Succeed()) mfRepo.SetData(model.MediaFiles{{ID: "mf2", AlbumID: "albm"}}) - img, err := svc.Get(ctx, model.MustParseArtworkID("mf-mf2"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mf2"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(coverBytes)) _, mfEnq := queueRepo.Data[primaryKey("mf", "mf2")] @@ -325,7 +325,7 @@ var _ = Describe("Artwork", func() { seedFoundStore("al", "albn", coverBytes) mfRepo.SetData(model.MediaFiles{{ID: "mf3", AlbumID: "albn", HasCoverArt: false}}) - img, err := svc.Get(ctx, model.MustParseArtworkID("mf-mf3"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mf3"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(coverBytes)) _, mfEnq := queueRepo.Data[primaryKey("mf", "mf3")] @@ -339,7 +339,7 @@ var _ = Describe("Artwork", func() { Path: "tests/fixtures/artist/an-album/test.mp3", LibraryID: 0, }}) - img, err := svc.Get(ctx, model.MustParseArtworkID("mf-mf4"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mf4"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(len(readAll(img))).To(BeNumerically(">", 0)) Expect(queueRepo.Data[primaryKey("mf", "mf4")].Priority).To(Equal(model.ArtworkPriorityBump)) @@ -353,7 +353,7 @@ var _ = Describe("Artwork", func() { seedFoundStore("al", "aldd", []byte("album-art-distinct")) // album's own found art differs mfRepo.SetData(model.MediaFiles{{ID: "mf5", AlbumID: "aldd", DiscNumber: 1, HasCoverArt: false}}) - img, err := svc.Get(ctx, model.MustParseArtworkID("mf-mf5"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mf5"), 0, false) Expect(err).ToNot(HaveOccurred()) // The disc-folder image, not the album's own art: proof it routed through serveDisc. Expect(readAll(img)).To(Equal(coverBytes)) @@ -369,7 +369,7 @@ var _ = Describe("Artwork", func() { albumRepo.SetData(model.Albums{{ID: "albad", Name: "Album"}}) seedFoundStore("al", "albad", coverBytes) - img, err := svc.Get(ctx, model.MustParseArtworkID("mf-mfbad"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mfbad"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(coverBytes), "a placeholder here would be worse than the album cover") }) @@ -381,7 +381,7 @@ var _ = Describe("Artwork", func() { seedFoundStore("al", "alsd", []byte("album-art-distinct")) mfRepo.SetData(model.MediaFiles{{ID: "mf6", AlbumID: "alsd", DiscNumber: 1, HasCoverArt: false}}) - img, err := svc.Get(ctx, model.MustParseArtworkID("mf-mf6"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mf6"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(coverBytes)) }) @@ -541,7 +541,7 @@ var _ = Describe("EntityExists", func() { DescribeTable("reports whether the owning entity is still there", func(id string, expected bool) { - Expect(entityExists(ctx, ds, model.MustParseArtworkID(id))).To(Equal(expected)) + Expect(entityExists(ctx, ds, tests.MustParseArtworkID(id))).To(Equal(expected)) }, Entry("existing album", "al-al1", true), Entry("deleted album", "al-gone", false), diff --git a/core/artwork/e2e/acquire_serve_test.go b/core/artwork/e2e/acquire_serve_test.go index 009612b4a..38ca3895e 100644 --- a/core/artwork/e2e/acquire_serve_test.go +++ b/core/artwork/e2e/acquire_serve_test.go @@ -130,7 +130,7 @@ var _ = Describe("Acquisition → serve loop", func() { bump("al", "al1") runWorkerUntil(ctx, worker, itemFound(model.KindAlbumArtwork, "al1")) - img, err := svc.Get(ctx, model.MustParseArtworkID("al-al1"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("al-al1"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(img.Placeholder).To(BeFalse()) Expect(readAll(img)).To(Equal(jxlFixture)) @@ -145,7 +145,7 @@ var _ = Describe("Acquisition → serve loop", func() { Expect(err).ToNot(HaveOccurred()) Expect(ia.Source).To(Equal("folder")) - img, err := svc.Get(ctx, model.MustParseArtworkID("al-al1"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("al-al1"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(img.Hash).To(Equal(ia.Hash)) Expect(img.Placeholder).To(BeFalse()) @@ -162,7 +162,7 @@ var _ = Describe("Acquisition → serve loop", func() { Expect(err).ToNot(HaveOccurred()) Expect(ia.Source).To(Equal("upload")) - img, err := svc.Get(ctx, model.MustParseArtworkID("ar-ar1"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("ar-ar1"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(img.Hash).To(Equal(ia.Hash)) Expect(readAll(img)).To(Equal(readFixture(artistPngFixture))) @@ -179,7 +179,7 @@ var _ = Describe("Acquisition → serve loop", func() { Expect(err).ToNot(HaveOccurred()) Expect(ia.Source).To(Equal("generated")) - img, err := svc.Get(ctx, model.MustParseArtworkID("pl-pl1"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("pl-pl1"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(img.Hash).To(Equal(ia.Hash)) art, err := artRepo.GetImage(ctx, ia.Hash) @@ -198,7 +198,7 @@ var _ = Describe("Acquisition → serve loop", func() { Expect(err).ToNot(HaveOccurred()) Expect(ia.Source).To(Equal("upload")) - img, err := svc.Get(ctx, model.MustParseArtworkID("ra-ra1"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("ra-ra1"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(img.Hash).To(Equal(ia.Hash)) Expect(readAll(img)).To(Equal(coverBytes)) @@ -209,7 +209,7 @@ var _ = Describe("Acquisition → serve loop", func() { ID: "mf1", AlbumID: "al1", HasCoverArt: true, LibraryID: 0, Path: mp3Fixture, }}) - provisional, err := svc.Get(ctx, model.MustParseArtworkID("mf-mf1"), 0, false) + provisional, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mf1"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(provisional.Placeholder).To(BeFalse()) Expect(provisional.Hash).ToNot(BeEmpty()) @@ -226,7 +226,7 @@ var _ = Describe("Acquisition → serve loop", func() { Expect(ia.Source).To(Equal("embedded")) Expect(ia.Hash).To(Equal(provisional.Hash)) - resolved, err := svc.Get(ctx, model.MustParseArtworkID("mf-mf1"), 0, false) + resolved, err := svc.Get(ctx, tests.MustParseArtworkID("mf-mf1"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(resolved.Hash).To(Equal(ia.Hash)) Expect(readAll(resolved)).To(Equal(provisionalBytes)) @@ -284,7 +284,7 @@ var _ = Describe("Acquisition → serve loop", func() { ia2, err := artRepo.GetItemArtwork(ctx, model.KindAlbumArtwork, "al2", model.ImageTypePrimary) Expect(err).ToNot(HaveOccurred()) Expect(ia1.Hash).To(Equal(ia2.Hash), "identical bytes must share one content hash") - Expect(readAll(mustGet(svc.Get(ctx, model.MustParseArtworkID("al-al2"), 0, false)))).To(Equal(coverBytes)) + Expect(readAll(mustGet(svc.Get(ctx, tests.MustParseArtworkID("al-al2"), 0, false)))).To(Equal(coverBytes)) }) It("stops serving a file-backed image once its source file changes underneath", func() { @@ -303,7 +303,7 @@ var _ = Describe("Acquisition → serve loop", func() { Expect(os.Chtimes(path, newer, newer)).To(Succeed()) // The mtime no longer matches the state row, so the stale bytes are not served. - _, err = svc.Get(ctx, model.MustParseArtworkID("ra-ra1"), 0, false) + _, err = svc.Get(ctx, tests.MustParseArtworkID("ra-ra1"), 0, false) Expect(err).To(MatchError(artwork.ErrUnavailable)) // That failed read enqueued a re-resolution. @@ -311,7 +311,7 @@ var _ = Describe("Acquisition → serve loop", func() { cur, gerr := artRepo.GetItemArtwork(ctx, model.KindRadioArtwork, "ra1", model.ImageTypePrimary) return gerr == nil && cur.Hash != "" && cur.Hash != staleHash }) - img, err := svc.Get(ctx, model.MustParseArtworkID("ra-ra1"), 0, false) + img, err := svc.Get(ctx, tests.MustParseArtworkID("ra-ra1"), 0, false) Expect(err).ToNot(HaveOccurred()) Expect(readAll(img)).To(Equal(readFixture(artistPngFixture))) }) @@ -321,7 +321,7 @@ var _ = Describe("Acquisition → serve loop", func() { bump("al", "alx") runWorkerUntil(ctx, worker, itemAbsent(model.KindAlbumArtwork, "alx")) - _, err := svc.Get(ctx, model.MustParseArtworkID("al-alx"), 0, false) + _, err := svc.Get(ctx, tests.MustParseArtworkID("al-alx"), 0, false) Expect(err).To(MatchError(artwork.ErrUnavailable)) img, err := svc.GetOrPlaceholder(ctx, "al-alx", 0, false) diff --git a/core/artwork/e2e/resolution_harness_test.go b/core/artwork/e2e/resolution_harness_test.go index 44c600bf8..9a428724c 100644 --- a/core/artwork/e2e/resolution_harness_test.go +++ b/core/artwork/e2e/resolution_harness_test.go @@ -324,19 +324,14 @@ func loadEmbeddedFixture() { } func extractEmbeddedArt(mp3 []byte) []byte { + GinkgoHelper() tf, err := taglib.OpenStream(bytes.NewReader(mp3)) - if err != nil { - panic("embedded-art fixture: taglib.OpenStream failed: " + err.Error()) - } + Expect(err).ToNot(HaveOccurred(), "embedded-art fixture: taglib.OpenStream failed") defer tf.Close() - images := tf.Properties().Images - if len(images) == 0 { - panic("embedded-art fixture has no embedded images") - } + Expect(tf.Properties().Images).ToNot(BeEmpty(), "embedded-art fixture has no embedded images") data, err := tf.Image(0) - if err != nil || len(data) == 0 { - panic("embedded-art fixture: could not read image 0") - } + Expect(err).ToNot(HaveOccurred(), "embedded-art fixture: could not read image 0") + Expect(data).ToNot(BeEmpty(), "embedded-art fixture: image 0 is empty") return data } diff --git a/core/artwork/worker_test.go b/core/artwork/worker_test.go index 83367ca05..e37faa865 100644 --- a/core/artwork/worker_test.go +++ b/core/artwork/worker_test.go @@ -148,7 +148,7 @@ type panickingAlbumRepo struct { func (r *panickingAlbumRepo) Get(ctx context.Context, id string) (*model.Album, error) { if id == r.panicID { - panic("boom") + panic("boom") //nolint:forbidigo } return r.MockAlbumRepo.Get(ctx, id) } diff --git a/core/playback/mpv/mpv_test.go b/core/playback/mpv/mpv_test.go index bdef96f26..5473f2ed3 100644 --- a/core/playback/mpv/mpv_test.go +++ b/core/playback/mpv/mpv_test.go @@ -2,7 +2,6 @@ package mpv import ( "context" - "fmt" "io" "os" "path/filepath" @@ -377,6 +376,7 @@ var _ = Describe("MPV", func() { // createMockMPVScript creates a mock script that outputs arguments to stdout func createMockMPVScript(tempDir string) string { + GinkgoHelper() var scriptContent string var scriptExt string @@ -402,10 +402,7 @@ done } scriptPath := filepath.Join(tempDir, "mock_mpv"+scriptExt) - err := os.WriteFile(scriptPath, []byte(scriptContent), 0755) //nolint:gosec - if err != nil { - panic(fmt.Sprintf("Failed to create mock script: %v", err)) - } + Expect(os.WriteFile(scriptPath, []byte(scriptContent), 0755)).To(Succeed()) //nolint:gosec return scriptPath } diff --git a/core/storage/storagetest/fake_storage.go b/core/storage/storagetest/fake_storage.go index f1ad643b4..ea95d6326 100644 --- a/core/storage/storagetest/fake_storage.go +++ b/core/storage/storagetest/fake_storage.go @@ -15,6 +15,8 @@ import ( "github.com/navidrome/navidrome/log" "github.com/navidrome/navidrome/model/metadata" "github.com/navidrome/navidrome/utils/random" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" ) // FakeStorage is a fake storage that provides a FakeFS. @@ -126,15 +128,11 @@ func (ffs *FakeFS) ClearError(filePath string) { } func (ffs *FakeFS) UpdateTags(filePath string, newTags map[string]any, when ...time.Time) { + ginkgo.GinkgoHelper() f, ok := ffs.MapFS[filePath] - if !ok { - panic(fmt.Errorf("file %s not found", filePath)) - } + gomega.Expect(ok).To(gomega.BeTrue(), "file %s not found", filePath) var tags map[string]any - err := json.Unmarshal(f.Data, &tags) - if err != nil { - panic(err) - } + gomega.Expect(json.Unmarshal(f.Data, &tags)).To(gomega.Succeed()) maps.Copy(tags, newTags) data, _ := json.Marshal(tags) f.Data = data diff --git a/core/stream/media_streamer.go b/core/stream/media_streamer.go index 8de09a4e1..ee9346876 100644 --- a/core/stream/media_streamer.go +++ b/core/stream/media_streamer.go @@ -206,7 +206,7 @@ func (s *Stream) Serve(ctx context.Context, w http.ResponseWriter, r *http.Reque return 0, fmt.Errorf("sending transcoded file: %w", err) } // The 200 is already sent, so dropping the connection is the only way to say "truncated". - panic(http.ErrAbortHandler) + panic(http.ErrAbortHandler) //nolint:forbidigo } if c == 0 { // Nothing is sent yet, so drop the estimate instead of padding a body that holds no audio. diff --git a/db/migrations/migration.go b/db/migrations/migration.go index df1c392a5..ffc944c39 100644 --- a/db/migrations/migration.go +++ b/db/migrations/migration.go @@ -8,6 +8,7 @@ import ( "sync" "github.com/navidrome/navidrome/consts" + "github.com/navidrome/navidrome/log" ) // Use this in migrations that need to communicate something important (breaking changes, forced reindexes, etc...) @@ -38,27 +39,16 @@ var ( func isDBInitialized(ctx context.Context, tx *sql.Tx) bool { once.Do(func() { - rows, err := tx.QueryContext(ctx, "select count(*) from property where id=?", consts.InitialSetupFlagKey) - checkErr(err) - initialized = checkCount(rows) > 0 + var count int + err := tx.QueryRowContext(ctx, "select count(*) from property where id=?", consts.InitialSetupFlagKey).Scan(&count) + if err != nil { + log.Error(ctx, "Could not check if the database is initialized", err) + } + initialized = count > 0 }) return initialized } -func checkCount(rows *sql.Rows) (count int) { - for rows.Next() { - err := rows.Scan(&count) - checkErr(err) - } - return count -} - -func checkErr(err error) { - if err != nil { - panic(err) - } -} - type ( execFunc func() error execStmtFunc func(stmt string) execFunc diff --git a/model/artwork_id.go b/model/artwork_id.go index e827e935a..a1d2dd2ae 100644 --- a/model/artwork_id.go +++ b/model/artwork_id.go @@ -123,14 +123,6 @@ func isImageHash(s string) bool { return true } -func MustParseArtworkID(id string) ArtworkID { - artID, err := ParseArtworkID(id) - if err != nil { - panic(artID) - } - return artID -} - func DiscArtworkID(albumID string, discNumber int) string { return fmt.Sprintf("%s:%d", albumID, discNumber) } diff --git a/model/criteria/criteria_test.go b/model/criteria/criteria_test.go index 5a8ebaa5c..29c9f4e50 100644 --- a/model/criteria/criteria_test.go +++ b/model/criteria/criteria_test.go @@ -61,9 +61,7 @@ var _ = Describe("Criteria", func() { "offset": 10 } `)) - if err != nil { - panic(err) - } + gomega.Expect(err).ToNot(gomega.HaveOccurred()) jsonObj = b.String() }) It("marshals to JSON", func() { diff --git a/persistence/persistence_suite_test.go b/persistence/persistence_suite_test.go index 67fc9b955..856655fe0 100644 --- a/persistence/persistence_suite_test.go +++ b/persistence/persistence_suite_test.go @@ -201,43 +201,20 @@ var _ = BeforeSuite(func() { ur := NewUserRepository(conn) for i := range testUsers { - err := ur.Put(ctx, &testUsers[i]) - if err != nil { - panic(err) - } - } - - // Associate users with library 1 (default test library) - for i := range testUsers { - err := ur.SetUserLibraries(ctx, testUsers[i].ID, []int{1}) - if err != nil { - panic(err) - } + Expect(ur.Put(ctx, &testUsers[i])).To(Succeed()) + Expect(ur.SetUserLibraries(ctx, testUsers[i].ID, []int{1})).To(Succeed()) } alr := NewAlbumRepository(conn).(*albumRepository) for i := range testAlbums { - err := alr.Put(ctx, new(testAlbums[i])) - if err != nil { - panic(err) - } + Expect(alr.Put(ctx, new(testAlbums[i]))).To(Succeed()) } arr := NewArtistRepository(conn) - for i := range testArtists { - err := arr.Put(ctx, new(testArtists[i])) - if err != nil { - panic(err) - } - } - - // Associate artists with library 1 (default test library) lr := NewLibraryRepository(conn) for i := range testArtists { - err := lr.AddArtist(ctx, 1, testArtists[i].ID) - if err != nil { - panic(err) - } + Expect(arr.Put(ctx, new(testArtists[i]))).To(Succeed()) + Expect(lr.AddArtist(ctx, 1, testArtists[i].ID)).To(Succeed()) } // Populate album_artists based on the AlbumArtistID relationships in testAlbums @@ -256,25 +233,17 @@ var _ = BeforeSuite(func() { "role": "artist", "sub_role": "", })) - if err != nil { - panic(err) - } + Expect(err).ToNot(HaveOccurred()) } mr := NewMediaFileRepository(conn) for i := range testSongs { - err := mr.Put(ctx, &testSongs[i]) - if err != nil { - panic(err) - } + Expect(mr.Put(ctx, &testSongs[i])).To(Succeed()) } rar := NewRadioRepository(conn) for i := range testRadios { - err := rar.Put(ctx, new(testRadios[i])) - if err != nil { - panic(err) - } + Expect(rar.Put(ctx, new(testRadios[i]))).To(Succeed()) } plsBest = model.Playlist{ @@ -292,48 +261,29 @@ var _ = BeforeSuite(func() { pr := NewPlaylistRepository(conn) for i := range testPlaylists { - err := pr.Put(ctx, testPlaylists[i]) - if err != nil { - panic(err) - } + Expect(pr.Put(ctx, testPlaylists[i])).To(Succeed()) } // Prepare annotations - if err := arr.SetStar(ctx, true, artistBeatles.ID); err != nil { - panic(err) - } + Expect(arr.SetStar(ctx, true, artistBeatles.ID)).To(Succeed()) ar, err := arr.Get(ctx, artistBeatles.ID) - if err != nil { - panic(err) - } - if ar == nil { - panic("artist not found after SetStar") - } + Expect(err).ToNot(HaveOccurred()) + Expect(ar).ToNot(BeNil(), "artist not found after SetStar") artistBeatles.Starred = true artistBeatles.StarredAt = ar.StarredAt testArtists[1] = artistBeatles - if err := alr.SetStar(ctx, true, albumRadioactivity.ID); err != nil { - panic(err) - } + Expect(alr.SetStar(ctx, true, albumRadioactivity.ID)).To(Succeed()) al, err := alr.Get(ctx, albumRadioactivity.ID) - if err != nil { - panic(err) - } - if al == nil { - panic("album not found after SetStar") - } + Expect(err).ToNot(HaveOccurred()) + Expect(al).ToNot(BeNil(), "album not found after SetStar") albumRadioactivity.Starred = true albumRadioactivity.StarredAt = al.StarredAt testAlbums[2] = albumRadioactivity - if err := mr.SetStar(ctx, true, songComeTogether.ID); err != nil { - panic(err) - } + Expect(mr.SetStar(ctx, true, songComeTogether.ID)).To(Succeed()) mf, err := mr.Get(ctx, songComeTogether.ID) - if err != nil { - panic(err) - } + Expect(err).ToNot(HaveOccurred()) songComeTogether.Starred = true songComeTogether.StarredAt = mf.StarredAt testSongs[1] = songComeTogether @@ -345,9 +295,7 @@ var _ = BeforeSuite(func() { "user_id": s.UserID, "submission_time": s.SubmissionTime, })) - if err != nil { - panic(err) - } + Expect(err).ToNot(HaveOccurred()) } }) diff --git a/persistence/playqueue_repository_test.go b/persistence/playqueue_repository_test.go index 6f438afb3..693be8a0b 100644 --- a/persistence/playqueue_repository_test.go +++ b/persistence/playqueue_repository_test.go @@ -397,11 +397,10 @@ var _ = Describe("PlayQueueRepository", func() { }) func countPlayQueues(repo model.PlayQueueRepository, userId string) int { + GinkgoHelper() r := repo.(*playQueueRepository) c, err := r.count(GinkgoT().Context(), squirrel.Select().Where(squirrel.Eq{"user_id": userId})) - if err != nil { - panic(err) - } + Expect(err).ToNot(HaveOccurred()) return int(c) } diff --git a/persistence/radio_repository_test.go b/persistence/radio_repository_test.go index aba776853..46fa50a60 100644 --- a/persistence/radio_repository_test.go +++ b/persistence/radio_repository_test.go @@ -34,10 +34,7 @@ var _ = Describe("RadioRepository", func() { } for i := range testRadios { - err := repo.Put(ctx, new(testRadios[i])) - if err != nil { - panic(err) - } + Expect(repo.Put(ctx, new(testRadios[i]))).To(Succeed()) } }) diff --git a/scanner/walk_dir_tree_test.go b/scanner/walk_dir_tree_test.go index 33015db35..409151ab8 100644 --- a/scanner/walk_dir_tree_test.go +++ b/scanner/walk_dir_tree_test.go @@ -754,13 +754,15 @@ func (fd *fakeDirFile) ReadDir(int) ([]fs.DirEntry, error) { } func getDirEntry(baseDir, name string) os.DirEntry { + GinkgoHelper() dirEntries, _ := os.ReadDir(baseDir) for _, entry := range dirEntries { if entry.Name() == name { return entry } } - panic(fmt.Sprintf("Could not find %s in %s", name, baseDir)) + Fail(fmt.Sprintf("Could not find %s in %s", name, baseDir)) + return nil } // newLocalMusicFS returns the production local storage MusicFS rooted at libRoot diff --git a/server/apiv1/api.go b/server/apiv1/api.go index a75de3d8d..a39fe8509 100644 --- a/server/apiv1/api.go +++ b/server/apiv1/api.go @@ -56,7 +56,7 @@ func problemRecoverer(next http.Handler) http.Handler { return } if err, ok := rec.(error); ok && errors.Is(err, http.ErrAbortHandler) { - panic(rec) + panic(rec) //nolint:forbidigo } log.Error(r.Context(), "API v1: panic in handler", "panic", rec, "stack", string(debug.Stack())) writeProblemStatus(w, r, http.StatusInternalServerError, ProblemCodeInternal, "") diff --git a/server/apiv1/api_test.go b/server/apiv1/api_test.go index 2552e40b0..20571a049 100644 --- a/server/apiv1/api_test.go +++ b/server/apiv1/api_test.go @@ -55,7 +55,7 @@ var _ = Describe("Router", func() { }) panicking := func(v any) http.Handler { - return problemRecoverer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { panic(v) })) + return problemRecoverer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { panic(v) })) //nolint:forbidigo } It("turns a handler panic into a 500 problem", func() { diff --git a/server/jellyfin/lyrics_test.go b/server/jellyfin/lyrics_test.go index 2c3921e22..f7c839f48 100644 --- a/server/jellyfin/lyrics_test.go +++ b/server/jellyfin/lyrics_test.go @@ -35,7 +35,7 @@ func (f *fakeLyricsService) GetLyrics(ctx context.Context, mf *model.MediaFile) } } if f.panicVal != nil { - panic(f.panicVal) + panic(f.panicVal) //nolint:forbidigo } if f.err != nil { return nil, f.err diff --git a/server/serve_index_test.go b/server/serve_index_test.go index b84738d22..2e0d9336b 100644 --- a/server/serve_index_test.go +++ b/server/serve_index_test.go @@ -3,7 +3,6 @@ package server import ( "context" "encoding/json" - "fmt" "net/http" "net/http/httptest" "os" @@ -324,18 +323,15 @@ var _ = Describe("addShareData", func() { var appConfigRegex = regexp.MustCompile(`(?m)window.__APP_CONFIG__=(.*);`) func extractAppConfig(body string) map[string]any { + GinkgoHelper() config := make(map[string]any) match := appConfigRegex.FindStringSubmatch(body) if match == nil { return config } str, err := strconv.Unquote(match[1]) - if err != nil { - panic(fmt.Sprintf("%s: %s", match[1], err)) - } - if err := json.Unmarshal([]byte(str), &config); err != nil { - panic(err) - } + Expect(err).ToNot(HaveOccurred(), match[1]) + Expect(json.Unmarshal([]byte(str), &config)).To(Succeed()) return config } diff --git a/server/subsonic/e2e/e2e_suite_test.go b/server/subsonic/e2e/e2e_suite_test.go index a81e44597..fc830952b 100644 --- a/server/subsonic/e2e/e2e_suite_test.go +++ b/server/subsonic/e2e/e2e_suite_test.go @@ -278,9 +278,8 @@ func doRawReqWithUser(user model.User, endpoint string, params ...string) *httpt // buildReq creates a GET request with Subsonic auth params (u, p, v, c, f=json). func buildReq(user model.User, endpoint string, params ...string) *http.Request { - if len(params)%2 != 0 { - panic("buildReq: odd number of parameters") - } + GinkgoHelper() + Expect(len(params)%2).To(BeZero(), "buildReq: odd number of parameters") q := url.Values{} q.Add("u", user.UserName) q.Add("p", "password") diff --git a/server/subsonic/middlewares_test.go b/server/subsonic/middlewares_test.go index a2f7f5800..5392cc61f 100644 --- a/server/subsonic/middlewares_test.go +++ b/server/subsonic/middlewares_test.go @@ -33,10 +33,9 @@ func newGetRequest(queryParams ...string) *http.Request { } func newPostRequest(queryParam string, formFields ...string) *http.Request { + GinkgoHelper() r, err := http.NewRequest("POST", "/ping?"+queryParam, strings.NewReader(strings.Join(formFields, "&"))) - if err != nil { - panic(err) - } + Expect(err).ToNot(HaveOccurred()) r.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value") ctx := r.Context() return r.WithContext(log.NewContext(ctx)) @@ -789,9 +788,7 @@ var _ = Describe("Middlewares", func() { var err error usr, err = ur.FindByUsernameWithPassword(ctx, "admin") - if err != nil { - panic(err) - } + Expect(err).ToNot(HaveOccurred()) }) Context("Plaintext password", func() { @@ -836,9 +833,7 @@ var _ = Describe("Middlewares", func() { usr = &model.User{UserName: "admin"} var err error validToken, err = auth.CreateToken(usr) - if err != nil { - panic(err) - } + Expect(err).ToNot(HaveOccurred()) }) It("authenticates with JWT token based authentication", func() { diff --git a/server/throttle_backlog_test.go b/server/throttle_backlog_test.go index 2a57422ca..2c11e3fa2 100644 --- a/server/throttle_backlog_test.go +++ b/server/throttle_backlog_test.go @@ -50,7 +50,7 @@ var _ = Describe("ThrottleBacklog", func() { r.Use(middleware.Recoverer) r.Use(m) r.Get("/panic", func(w http.ResponseWriter, r *http.Request) { - panic("boom") + panic("boom") //nolint:forbidigo }) r.Get("/test", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("ok")) diff --git a/tests/test_helpers.go b/tests/test_helpers.go index b1cb041ad..c6c75916f 100644 --- a/tests/test_helpers.go +++ b/tests/test_helpers.go @@ -8,8 +8,10 @@ import ( "github.com/navidrome/navidrome/db" "github.com/navidrome/navidrome/log" + "github.com/navidrome/navidrome/model" "github.com/navidrome/navidrome/model/id" "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" ) @@ -79,3 +81,10 @@ func LogHook() (*test.Hook, func()) { log.SetDefaultLogger(logrus.New()) } } + +func MustParseArtworkID(id string) model.ArtworkID { + ginkgo.GinkgoHelper() + artID, err := model.ParseArtworkID(id) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + return artID +} diff --git a/utils/cache/simple_cache_test.go b/utils/cache/simple_cache_test.go index 1c4f5c9bb..0b899cb45 100644 --- a/utils/cache/simple_cache_test.go +++ b/utils/cache/simple_cache_test.go @@ -145,7 +145,7 @@ var _ = Describe("SimpleCache", func() { It("cleans up the in-flight registration when the loader panics", func() { Expect(func() { _, _ = cache.GetWithLoader("key", func(string) (string, time.Duration, error) { - panic("boom") + panic("boom") //nolint:forbidigo }) }).To(PanicWith("boom")) diff --git a/utils/merge/merge_fs_test.go b/utils/merge/merge_fs_test.go index 7241308d2..e5ef55097 100644 --- a/utils/merge/merge_fs_test.go +++ b/utils/merge/merge_fs_test.go @@ -104,11 +104,10 @@ var _ = Describe("FS", func() { }) func _f(dir, name string, content ...string) string { + GinkgoHelper() path := filepath.Join(dir, name) file, err := os.Create(path) - if err != nil { - panic(err) - } + Expect(err).ToNot(HaveOccurred()) if len(content) > 0 { _, _ = file.WriteString(content[0]) }