mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-19 15:23:36 +00:00
resizedItem.Reader closes what open() hands back, so an open() that reports "no image" as (nil, nil) rather than an error takes the request down with a nil-pointer panic. Every caller returns an error today, and no test covered it: the resolution e2e harness stubs the resize reader out entirely, so no e2e path reaches this code at all. Guard it and cover Reader directly.
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package artwork
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"strings"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("resizedItem", func() {
|
|
Describe("Reader", func() {
|
|
newItem := func(open func() (io.ReadCloser, error)) *resizedItem {
|
|
return &resizedItem{hash: "abc123", size: 300, open: open}
|
|
}
|
|
|
|
It("reports a nil reader as unavailable instead of panicking on it", func() {
|
|
// Every caller is expected to report "no image" as an error, but a nil reader reaches
|
|
// the deferred Close as a nil interface, which takes the whole request down.
|
|
_, err := newItem(func() (io.ReadCloser, error) { return nil, nil }).Reader(context.Background())
|
|
Expect(err).To(MatchError(ErrUnavailable))
|
|
})
|
|
|
|
It("propagates the open error", func() {
|
|
boom := errors.New("boom")
|
|
_, err := newItem(func() (io.ReadCloser, error) { return nil, boom }).Reader(context.Background())
|
|
Expect(err).To(MatchError(boom))
|
|
})
|
|
|
|
It("serves the original bytes when they cannot be resized", func() {
|
|
rc, err := newItem(func() (io.ReadCloser, error) {
|
|
return io.NopCloser(strings.NewReader("not an image")), nil
|
|
}).Reader(context.Background())
|
|
Expect(err).ToNot(HaveOccurred())
|
|
defer rc.Close()
|
|
Expect(io.ReadAll(rc)).To(Equal([]byte("not an image")))
|
|
})
|
|
})
|
|
})
|