mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-19 15:23:36 +00:00
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.
This commit is contained in:
parent
3679b6215d
commit
2e7e24a023
@ -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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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")))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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())
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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())
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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, "")
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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__=(.*);</script>`)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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"))
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
2
utils/cache/simple_cache_test.go
vendored
2
utils/cache/simple_cache_test.go
vendored
@ -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"))
|
||||
|
||||
|
||||
@ -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])
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user