mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-19 15:23:36 +00:00
chore(lint): ban context.Background in tests, flag unused nolints (#6474)
* chore(lint): ban context.Background in tests, flag unused nolints Add a forbidigo rule that rejects context.Background and context.TODO in _test.go files. The lint message points to the right fix: the spec's ctx from GinkgoT().Context(), or t.Context() and b.Context() in plain tests and benchmarks. AGENTS.md already asks for this, but nothing enforced it, so new tests kept adding Background calls. All 465 existing calls are replaced, with one ctx per top-level Describe set at the top of its BeforeEach. The migration forbidigo rules keep their old scope through an exclusion matched on their message text. Also enable nolintlint with require-specific and allow-unused: false. It found 41 //nolint directives that suppressed nothing, or named no linter, or had a leading space that made them inert. They are removed or fixed. The sweep also fixed a middleware test that wrote a user with a nil ctx before ctx was set. * test: keep cleanup ROLLBACKs and the scanner singleton off the spec ctx The ROLLBACK cleanups in the library, plugin and initial setup tests must run even if the spec context is already cancelled, so they use context.WithoutCancel. The same goes for the context handed to the process-wide scanner singleton in the GetInstance test. Also document that the forbidigo exclusions are scoped by message text. * test: pass the caller's ctx to tests.ClearDB ClearDB was the last context.Background call in shared test code. It now takes a ctx, and every caller passes its spec ctx. The forbidigo rule for tests also covers the tests/ helper package now, so new helpers there cannot add Background calls either.
This commit is contained in:
parent
69377527bc
commit
dfe90ba384
@ -22,6 +22,7 @@ linters:
|
||||
- misspell
|
||||
- nakedret
|
||||
- nilerr
|
||||
- nolintlint
|
||||
- rowserrcheck
|
||||
- unconvert
|
||||
- whitespace
|
||||
@ -49,6 +50,11 @@ linters:
|
||||
msg: "use tx.QueryContext(ctx, ...) in migrations to propagate context"
|
||||
- pattern: 'tx\.QueryRow$'
|
||||
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()"
|
||||
nolintlint:
|
||||
require-specific: true
|
||||
allow-unused: false
|
||||
govet:
|
||||
enable:
|
||||
- nilness
|
||||
@ -61,9 +67,15 @@ linters:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- containedctx
|
||||
# forbidigo rules are scoped by their msg: "in migrations" or "in tests use"
|
||||
- path-except: 'db/migrations/'
|
||||
linters:
|
||||
- forbidigo
|
||||
text: "in migrations"
|
||||
- path-except: '(_test\.go|^tests/)'
|
||||
linters:
|
||||
- forbidigo
|
||||
text: "in tests use"
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
|
||||
@ -65,7 +65,7 @@ func (c *client) getJWT(ctx context.Context) (string, error) {
|
||||
}
|
||||
|
||||
type authResponse struct {
|
||||
JWT string `json:"jwt"` //nolint:gosec
|
||||
JWT string `json:"jwt"`
|
||||
}
|
||||
|
||||
var result authResponse
|
||||
|
||||
@ -20,9 +20,9 @@ var _ = Describe("JWT Authentication", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
httpClient = &fakeHttpClient{}
|
||||
client = newClient(httpClient)
|
||||
ctx = context.Background()
|
||||
})
|
||||
|
||||
Describe("getJWT", func() {
|
||||
|
||||
@ -21,7 +21,7 @@ var _ = Describe("deezerAgent", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
conf.Update(func(c *conf.Options) { c.Deezer.Enabled = true })
|
||||
})
|
||||
|
||||
|
||||
@ -29,8 +29,8 @@ var _ = Describe("lastfmAgent", func() {
|
||||
var ds model.DataStore
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
ds = &tests.MockDataStore{}
|
||||
ctx = context.Background()
|
||||
conf.Update(func(c *conf.Options) {
|
||||
c.LastFM.Enabled = true
|
||||
c.LastFM.ApiKey = "123"
|
||||
|
||||
@ -122,7 +122,7 @@ func (s *Router) callback(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, _ = w.Write([]byte("An error occurred while authorizing with Last.fm. \n\nRequest ID: " + middleware.GetReqID(ctx))) //nolint:gosec
|
||||
_, _ = w.Write([]byte("An error occurred while authorizing with Last.fm. \n\nRequest ID: " + middleware.GetReqID(ctx)))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -19,8 +19,10 @@ import (
|
||||
var _ = Describe("client", func() {
|
||||
var httpClient *tests.FakeHttpClient
|
||||
var client *client
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
httpClient = &tests.FakeHttpClient{}
|
||||
client = newClient("API_KEY", "SECRET", httpClient)
|
||||
})
|
||||
@ -30,7 +32,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.album.getinfo.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
album, err := client.albumGetInfo(context.Background(), "Believe", "U2", "mbid-1234", "pt")
|
||||
album, err := client.albumGetInfo(ctx, "Believe", "U2", "mbid-1234", "pt")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(album.Name).To(Equal("Believe"))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(apiBaseUrl + "?album=Believe&api_key=API_KEY&artist=U2&format=json&lang=pt&mbid=mbid-1234&method=album.getInfo"))
|
||||
@ -40,7 +42,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.album.getinfo.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
_, err := client.albumGetInfo(context.Background(), "Lungs", "Florence + the Machine", "", "en")
|
||||
_, err := client.albumGetInfo(ctx, "Lungs", "Florence + the Machine", "", "en")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.URL.Query().Get("artist")).To(Equal("Florence + the Machine"))
|
||||
})
|
||||
@ -51,7 +53,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.artist.getinfo.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
artist, err := client.artistGetInfo(context.Background(), "U2", "pt")
|
||||
artist, err := client.artistGetInfo(ctx, "U2", "pt")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(artist.Name).To(Equal("U2"))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(apiBaseUrl + "?api_key=API_KEY&artist=U2&format=json&lang=pt&method=artist.getInfo"))
|
||||
@ -61,7 +63,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.artist.getinfo.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
_, err := client.artistGetInfo(context.Background(), "Florence + the Machine", "en")
|
||||
_, err := client.artistGetInfo(ctx, "Florence + the Machine", "en")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.URL.Query().Get("artist")).To(Equal("Florence %2B the Machine"))
|
||||
})
|
||||
@ -72,7 +74,7 @@ var _ = Describe("client", func() {
|
||||
StatusCode: 500,
|
||||
}
|
||||
|
||||
_, err := client.artistGetInfo(context.Background(), "U2", "pt")
|
||||
_, err := client.artistGetInfo(ctx, "U2", "pt")
|
||||
Expect(err).To(MatchError("last.fm http status: (500)"))
|
||||
})
|
||||
|
||||
@ -82,7 +84,7 @@ var _ = Describe("client", func() {
|
||||
StatusCode: 400,
|
||||
}
|
||||
|
||||
_, err := client.artistGetInfo(context.Background(), "U2", "pt")
|
||||
_, err := client.artistGetInfo(ctx, "U2", "pt")
|
||||
Expect(err).To(MatchError(&lastFMError{Code: 3, Message: "Invalid Method - No method with that name in this package"}))
|
||||
})
|
||||
|
||||
@ -92,14 +94,14 @@ var _ = Describe("client", func() {
|
||||
StatusCode: 200,
|
||||
}
|
||||
|
||||
_, err := client.artistGetInfo(context.Background(), "U2", "pt")
|
||||
_, err := client.artistGetInfo(ctx, "U2", "pt")
|
||||
Expect(err).To(MatchError(&lastFMError{Code: 6, Message: "The artist you supplied could not be found"}))
|
||||
})
|
||||
|
||||
It("fails if HttpClient.Do() returns error", func() {
|
||||
httpClient.Err = errors.New("generic error")
|
||||
|
||||
_, err := client.artistGetInfo(context.Background(), "U2", "pt")
|
||||
_, err := client.artistGetInfo(ctx, "U2", "pt")
|
||||
Expect(err).To(MatchError("generic error"))
|
||||
})
|
||||
|
||||
@ -109,7 +111,7 @@ var _ = Describe("client", func() {
|
||||
StatusCode: 200,
|
||||
}
|
||||
|
||||
_, err := client.artistGetInfo(context.Background(), "U2", "pt")
|
||||
_, err := client.artistGetInfo(ctx, "U2", "pt")
|
||||
Expect(err).To(MatchError("invalid character '<' looking for beginning of value"))
|
||||
})
|
||||
|
||||
@ -120,7 +122,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.artist.getsimilar.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
similar, err := client.artistGetSimilar(context.Background(), "U2", 2)
|
||||
similar, err := client.artistGetSimilar(ctx, "U2", 2)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(similar.Artists)).To(Equal(2))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(apiBaseUrl + "?api_key=API_KEY&artist=U2&format=json&limit=2&method=artist.getSimilar"))
|
||||
@ -130,7 +132,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.artist.getsimilar.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
_, err := client.artistGetSimilar(context.Background(), "+44", 2)
|
||||
_, err := client.artistGetSimilar(ctx, "+44", 2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.URL.Query().Get("artist")).To(Equal("%2B44"))
|
||||
})
|
||||
@ -141,7 +143,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.artist.gettoptracks.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
top, err := client.artistGetTopTracks(context.Background(), "U2", 2)
|
||||
top, err := client.artistGetTopTracks(ctx, "U2", 2)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(top.Track)).To(Equal(2))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(apiBaseUrl + "?api_key=API_KEY&artist=U2&format=json&limit=2&method=artist.getTopTracks"))
|
||||
@ -151,7 +153,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.artist.gettoptracks.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
_, err := client.artistGetTopTracks(context.Background(), "C+C Music Factory", 2)
|
||||
_, err := client.artistGetTopTracks(ctx, "C+C Music Factory", 2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.URL.Query().Get("artist")).To(Equal("C%2BC Music Factory"))
|
||||
})
|
||||
@ -162,7 +164,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.track.getsimilar.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
similar, err := client.trackGetSimilar(context.Background(), "Just Can't Get Enough", "Depeche Mode", 5)
|
||||
similar, err := client.trackGetSimilar(ctx, "Just Can't Get Enough", "Depeche Mode", 5)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(similar.Track)).To(Equal(5))
|
||||
Expect(similar.Track[0].Name).To(Equal("Dreaming of Me"))
|
||||
@ -175,7 +177,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.track.getsimilar.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
_, err := client.trackGetSimilar(context.Background(), "1+1", "Queen + Paul Rodgers", 5)
|
||||
_, err := client.trackGetSimilar(ctx, "1+1", "Queen + Paul Rodgers", 5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
query := httpClient.SavedRequest.URL.Query()
|
||||
Expect(query.Get("track")).To(Equal("1%2B1"))
|
||||
@ -186,7 +188,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/lastfm.track.getsimilar.unknown.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
|
||||
similar, err := client.trackGetSimilar(context.Background(), "UnknownTrack", "UnknownArtist", 3)
|
||||
similar, err := client.trackGetSimilar(ctx, "UnknownTrack", "UnknownArtist", 3)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(similar.Track).To(BeEmpty())
|
||||
})
|
||||
@ -199,7 +201,7 @@ var _ = Describe("client", func() {
|
||||
StatusCode: 200,
|
||||
}
|
||||
|
||||
Expect(client.GetToken(context.Background())).To(Equal("TOKEN"))
|
||||
Expect(client.GetToken(ctx)).To(Equal("TOKEN"))
|
||||
queryParams := httpClient.SavedRequest.URL.Query()
|
||||
Expect(queryParams.Get("method")).To(Equal("auth.getToken"))
|
||||
Expect(queryParams.Get("format")).To(Equal("json"))
|
||||
@ -215,7 +217,7 @@ var _ = Describe("client", func() {
|
||||
StatusCode: 200,
|
||||
}
|
||||
|
||||
Expect(client.getSession(context.Background(), "TOKEN")).To(Equal("SESSION_KEY"))
|
||||
Expect(client.getSession(ctx, "TOKEN")).To(Equal("SESSION_KEY"))
|
||||
queryParams := httpClient.SavedRequest.URL.Query()
|
||||
Expect(queryParams.Get("method")).To(Equal("auth.getSession"))
|
||||
Expect(queryParams.Get("format")).To(Equal("json"))
|
||||
@ -240,7 +242,7 @@ var _ = Describe("client", func() {
|
||||
duration: 276,
|
||||
albumArtist: "U2",
|
||||
}
|
||||
err := client.scrobble(context.Background(), "SESSION_KEY", info)
|
||||
err := client.scrobble(ctx, "SESSION_KEY", info)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
req := httpClient.SavedRequest
|
||||
@ -274,7 +276,7 @@ var _ = Describe("client", func() {
|
||||
duration: 276,
|
||||
albumArtist: "U2",
|
||||
}
|
||||
err := client.updateNowPlaying(context.Background(), "SESSION_KEY", info)
|
||||
err := client.updateNowPlaying(ctx, "SESSION_KEY", info)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
req := httpClient.SavedRequest
|
||||
|
||||
@ -28,8 +28,8 @@ var _ = Describe("listenBrainzAgent", func() {
|
||||
var track *model.MediaFile
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
ds = &tests.MockDataStore{}
|
||||
ctx = context.Background()
|
||||
_ = ds.UserProps().Put(ctx, "user-1", sessionKeyProperty, "SK-1")
|
||||
httpClient = &tests.FakeHttpClient{}
|
||||
agent = listenBrainzConstructor(ds)
|
||||
|
||||
@ -64,7 +64,7 @@ type listenBrainzResponse struct {
|
||||
}
|
||||
|
||||
type listenBrainzRequest struct {
|
||||
ApiKey string //nolint:gosec
|
||||
ApiKey string
|
||||
Body listenBrainzRequestBody
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,9 @@ import (
|
||||
var _ = Describe("client", func() {
|
||||
var httpClient *tests.FakeHttpClient
|
||||
var client *client
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
httpClient = &tests.FakeHttpClient{}
|
||||
client = newClient("BASE_URL/", httpClient)
|
||||
})
|
||||
@ -51,7 +53,7 @@ var _ = Describe("client", func() {
|
||||
})
|
||||
|
||||
It("formats the request properly", func() {
|
||||
_, err := client.validateToken(context.Background(), "LB-TOKEN")
|
||||
_, err := client.validateToken(ctx, "LB-TOKEN")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal("BASE_URL/validate-token"))
|
||||
@ -60,7 +62,7 @@ var _ = Describe("client", func() {
|
||||
})
|
||||
|
||||
It("parses and returns the response", func() {
|
||||
res, err := client.validateToken(context.Background(), "LB-TOKEN")
|
||||
res, err := client.validateToken(ctx, "LB-TOKEN")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(res.Valid).To(Equal(true))
|
||||
Expect(res.UserName).To(Equal("ListenBrainzUser"))
|
||||
@ -93,7 +95,7 @@ var _ = Describe("client", func() {
|
||||
|
||||
Describe("updateNowPlaying", func() {
|
||||
It("formats the request properly", func() {
|
||||
Expect(client.updateNowPlaying(context.Background(), "LB-TOKEN", li)).To(Succeed())
|
||||
Expect(client.updateNowPlaying(ctx, "LB-TOKEN", li)).To(Succeed())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodPost))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal("BASE_URL/submit-listens"))
|
||||
Expect(httpClient.SavedRequest.Header.Get("Authorization")).To(Equal("Token LB-TOKEN"))
|
||||
@ -111,7 +113,7 @@ var _ = Describe("client", func() {
|
||||
})
|
||||
|
||||
It("formats the request properly", func() {
|
||||
Expect(client.scrobble(context.Background(), "LB-TOKEN", li)).To(Succeed())
|
||||
Expect(client.scrobble(ctx, "LB-TOKEN", li)).To(Succeed())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodPost))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal("BASE_URL/submit-listens"))
|
||||
Expect(httpClient.SavedRequest.Header.Get("Authorization")).To(Equal("Token LB-TOKEN"))
|
||||
@ -131,7 +133,7 @@ var _ = Describe("client", func() {
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"code": 400,"error": "artist mbid 1 is not valid."}`)),
|
||||
StatusCode: 400,
|
||||
}
|
||||
_, err := client.getArtistUrl(context.Background(), "1")
|
||||
_, err := client.getArtistUrl(ctx, "1")
|
||||
Expect(err.Error()).To(Equal("ListenBrainz error(400): artist mbid 1 is not valid."))
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(baseUrl + "artist_mbids=1"))
|
||||
@ -143,7 +145,7 @@ var _ = Describe("client", func() {
|
||||
Body: io.NopCloser(bytes.NewBufferString(``)),
|
||||
StatusCode: 501,
|
||||
}
|
||||
_, err := client.getArtistUrl(context.Background(), "1")
|
||||
_, err := client.getArtistUrl(ctx, "1")
|
||||
Expect(err.Error()).To(Equal("ListenBrainz: HTTP Error, Status: (501)"))
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(baseUrl + "artist_mbids=1"))
|
||||
@ -153,7 +155,7 @@ var _ = Describe("client", func() {
|
||||
It("It returns not found when the artist has no official homepage", func() {
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.artist.metadata.no_homepage.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
_, err := client.getArtistUrl(context.Background(), "7c2cc610-f998-43ef-a08f-dae3344b8973")
|
||||
_, err := client.getArtistUrl(ctx, "7c2cc610-f998-43ef-a08f-dae3344b8973")
|
||||
Expect(err.Error()).To(Equal("listenbrainz: not found"))
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(baseUrl + "artist_mbids=7c2cc610-f998-43ef-a08f-dae3344b8973"))
|
||||
@ -163,7 +165,7 @@ var _ = Describe("client", func() {
|
||||
It("It returns data when the artist has a homepage", func() {
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.artist.metadata.homepage.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
url, err := client.getArtistUrl(context.Background(), "d2a92ee2-27ce-4e71-bfc5-12e34fe8ef56")
|
||||
url, err := client.getArtistUrl(ctx, "d2a92ee2-27ce-4e71-bfc5-12e34fe8ef56")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(url).To(Equal("http://projectmili.com/"))
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
@ -180,7 +182,7 @@ var _ = Describe("client", func() {
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{"code":400,"error":"artist_mbid: '1' is not a valid uuid"}`)),
|
||||
StatusCode: 400,
|
||||
}
|
||||
_, err := client.getArtistTopSongs(context.Background(), "1", 50)
|
||||
_, err := client.getArtistTopSongs(ctx, "1", 50)
|
||||
Expect(err.Error()).To(Equal("ListenBrainz error(400): artist_mbid: '1' is not a valid uuid"))
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(baseUrl + "1"))
|
||||
@ -192,7 +194,7 @@ var _ = Describe("client", func() {
|
||||
Body: io.NopCloser(bytes.NewBufferString(``)),
|
||||
StatusCode: 500,
|
||||
}
|
||||
_, err := client.getArtistTopSongs(context.Background(), "1", 1)
|
||||
_, err := client.getArtistTopSongs(ctx, "1", 1)
|
||||
Expect(err.Error()).To(Equal("ListenBrainz: HTTP Error, Status: (500)"))
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(baseUrl + "1"))
|
||||
@ -202,7 +204,7 @@ var _ = Describe("client", func() {
|
||||
It("It returns all tracks when given the opportunity", func() {
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.popularity.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
data, err := client.getArtistTopSongs(context.Background(), "d2a92ee2-27ce-4e71-bfc5-12e34fe8ef56", 5)
|
||||
data, err := client.getArtistTopSongs(ctx, "d2a92ee2-27ce-4e71-bfc5-12e34fe8ef56", 5)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(data).To(Equal([]trackInfo{
|
||||
{
|
||||
@ -232,7 +234,7 @@ var _ = Describe("client", func() {
|
||||
It("It returns a subset of tracks when allowed", func() {
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.popularity.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
data, err := client.getArtistTopSongs(context.Background(), "d2a92ee2-27ce-4e71-bfc5-12e34fe8ef56", 1)
|
||||
data, err := client.getArtistTopSongs(ctx, "d2a92ee2-27ce-4e71-bfc5-12e34fe8ef56", 1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(data).To(Equal([]trackInfo{
|
||||
{
|
||||
@ -269,7 +271,7 @@ var _ = Describe("client", func() {
|
||||
Body: io.NopCloser(bytes.NewBufferString(`Bad request`)),
|
||||
StatusCode: 400,
|
||||
}
|
||||
_, err := client.getSimilarArtists(context.Background(), "1", 2)
|
||||
_, err := client.getSimilarArtists(ctx, "1", 2)
|
||||
Expect(err.Error()).To(Equal("ListenBrainz: HTTP Error, Status: (400)"))
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(getUrl("1")))
|
||||
@ -279,7 +281,7 @@ var _ = Describe("client", func() {
|
||||
It("handles real data properly", func() {
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.labs.similar-artists.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
resp, err := client.getSimilarArtists(context.Background(), mbid, 2)
|
||||
resp, err := client.getSimilarArtists(ctx, mbid, 2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(getUrl(mbid)))
|
||||
@ -293,7 +295,7 @@ var _ = Describe("client", func() {
|
||||
It("truncates data when requested", func() {
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.labs.similar-artists.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
resp, err := client.getSimilarArtists(context.Background(), "db92a151-1ac2-438b-bc43-b82e149ddd50", 1)
|
||||
resp, err := client.getSimilarArtists(ctx, "db92a151-1ac2-438b-bc43-b82e149ddd50", 1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(getUrl(mbid)))
|
||||
@ -309,7 +311,7 @@ var _ = Describe("client", func() {
|
||||
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.labs.similar-artists.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
resp, err := client.getSimilarArtists(context.Background(), mbid, 2)
|
||||
resp, err := client.getSimilarArtists(ctx, mbid, 2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(getUrl(mbid)))
|
||||
@ -339,7 +341,7 @@ var _ = Describe("client", func() {
|
||||
Body: io.NopCloser(bytes.NewBufferString(`Bad request`)),
|
||||
StatusCode: 400,
|
||||
}
|
||||
_, err := client.getSimilarRecordings(context.Background(), "1", 2)
|
||||
_, err := client.getSimilarRecordings(ctx, "1", 2)
|
||||
Expect(err.Error()).To(Equal("ListenBrainz: HTTP Error, Status: (400)"))
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(getUrl("1")))
|
||||
@ -349,7 +351,7 @@ var _ = Describe("client", func() {
|
||||
It("handles real data properly", func() {
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.labs.similar-recordings.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
resp, err := client.getSimilarRecordings(context.Background(), mbid, 2)
|
||||
resp, err := client.getSimilarRecordings(ctx, mbid, 2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(getUrl(mbid)))
|
||||
@ -377,7 +379,7 @@ var _ = Describe("client", func() {
|
||||
It("truncates data when requested", func() {
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.labs.similar-recordings.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
resp, err := client.getSimilarRecordings(context.Background(), mbid, 1)
|
||||
resp, err := client.getSimilarRecordings(ctx, mbid, 1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(getUrl(mbid)))
|
||||
@ -398,7 +400,7 @@ var _ = Describe("client", func() {
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.labs.similar-recordings-real-out-of-order.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
// There are actually 5 items. The dedup should happen FIRST
|
||||
resp, err := client.getSimilarRecordings(context.Background(), mbid, 4)
|
||||
resp, err := client.getSimilarRecordings(ctx, mbid, 4)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(getUrl(mbid)))
|
||||
@ -445,7 +447,7 @@ var _ = Describe("client", func() {
|
||||
|
||||
f, _ := os.Open("tests/fixtures/listenbrainz.labs.similar-recordings.json")
|
||||
httpClient.Res = http.Response{Body: f, StatusCode: 200}
|
||||
resp, err := client.getSimilarRecordings(context.Background(), mbid, 1)
|
||||
resp, err := client.getSimilarRecordings(ctx, mbid, 1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(httpClient.SavedRequest.Method).To(Equal(http.MethodGet))
|
||||
Expect(httpClient.SavedRequest.URL.String()).To(Equal(getUrl(mbid)))
|
||||
@ -470,7 +472,7 @@ var _ = Describe("client", func() {
|
||||
Header: http.Header{"X-Ratelimit-Reset-In": []string{"3"}},
|
||||
Body: io.NopCloser(strings.NewReader(`{"code":429,"error":"You have exceeded your rate limit."}`)),
|
||||
}
|
||||
_, err := client.validateToken(context.Background(), "token")
|
||||
_, err := client.validateToken(ctx, "token")
|
||||
Expect(errors.Is(err, agents.ErrRetryLater)).To(BeTrue())
|
||||
retry, ok := errors.AsType[*agents.RetryLaterError](err)
|
||||
Expect(ok).To(BeTrue())
|
||||
@ -482,7 +484,7 @@ var _ = Describe("client", func() {
|
||||
StatusCode: 429,
|
||||
Body: io.NopCloser(strings.NewReader(`{"code":429,"error":"rate limited"}`)),
|
||||
}
|
||||
_, err := client.validateToken(context.Background(), "token")
|
||||
_, err := client.validateToken(ctx, "token")
|
||||
Expect(errors.Is(err, agents.ErrRetryLater)).To(BeTrue())
|
||||
retry, _ := errors.AsType[*agents.RetryLaterError](err)
|
||||
Expect(retry.RetryIn).To(BeZero())
|
||||
@ -495,7 +497,7 @@ var _ = Describe("client", func() {
|
||||
Header: http.Header{"X-Ratelimit-Reset-In": []string{header}},
|
||||
Body: io.NopCloser(strings.NewReader(`{"code":429,"error":"rate limited"}`)),
|
||||
}
|
||||
_, err := client.validateToken(context.Background(), "token")
|
||||
_, err := client.validateToken(ctx, "token")
|
||||
retry, _ := errors.AsType[*agents.RetryLaterError](err)
|
||||
Expect(retry.RetryIn).To(Equal(time.Hour))
|
||||
},
|
||||
@ -511,7 +513,7 @@ var _ = Describe("client", func() {
|
||||
Header: http.Header{"X-Ratelimit-Reset-In": []string{"7"}},
|
||||
Body: io.NopCloser(strings.NewReader(`{"code":429,"error":"You have exceeded your rate limit."}`)),
|
||||
}
|
||||
_, err := client.validateToken(context.Background(), "token")
|
||||
_, err := client.validateToken(ctx, "token")
|
||||
Expect(errors.Is(err, agents.ErrRetryLater)).To(BeTrue())
|
||||
retry, ok := errors.AsType[*agents.RetryLaterError](err)
|
||||
Expect(ok).To(BeTrue())
|
||||
@ -524,7 +526,7 @@ var _ = Describe("client", func() {
|
||||
Header: http.Header{"X-Ratelimit-Reset-In": []string{"5"}},
|
||||
Body: io.NopCloser(strings.NewReader(`{"code":429,"error":"rate limited"}`)),
|
||||
}
|
||||
_, err := client.getArtistUrl(context.Background(), "1")
|
||||
_, err := client.getArtistUrl(ctx, "1")
|
||||
Expect(errors.Is(err, agents.ErrRetryLater)).To(BeTrue())
|
||||
retry, ok := errors.AsType[*agents.RetryLaterError](err)
|
||||
Expect(ok).To(BeTrue())
|
||||
|
||||
@ -55,9 +55,10 @@ var _ = Describe("parseArtworkKind", func() {
|
||||
|
||||
var _ = Describe("resolveArtworkTargets", func() {
|
||||
var ds *tests.MockDataStore
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
artists := tests.CreateMockArtistRepo()
|
||||
artists.SetData(model.Artists{{ID: "artist1"}})
|
||||
ds = &tests.MockDataStore{MockedArtist: artists}
|
||||
@ -474,7 +475,10 @@ var _ = Describe("artwork reprocess selection", func() {
|
||||
})
|
||||
|
||||
var _ = Describe("explain/reprocess source round trip", func() {
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
// storedSource reads back the Source line explain printed, as an operator would copy it.
|
||||
storedSource := func(out string) string {
|
||||
@ -566,7 +570,7 @@ var _ = Describe("reprocessArtwork", func() {
|
||||
var queue *tests.MockArtworkQueueRepo
|
||||
var out strings.Builder
|
||||
var imageAgents artwork.ImageAgentCount
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
kinds := []model.Kind{model.KindArtistArtwork, model.KindAlbumArtwork}
|
||||
accept := func(io.Writer, int64, int64) bool { return true }
|
||||
decline := func(io.Writer, int64, int64) bool { return false }
|
||||
@ -577,6 +581,7 @@ var _ = Describe("reprocessArtwork", func() {
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
conf.Update(func(c *conf.Options) {
|
||||
c.CoverArtPriority = "cover.*, external"
|
||||
c.ArtistArtPriority = "artist.*, external"
|
||||
@ -814,9 +819,10 @@ var _ = Describe("collectStatus", func() {
|
||||
var ds *tests.MockDataStore
|
||||
var art *tests.MockArtworkRepo
|
||||
var queue *tests.MockArtworkQueueRepo
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
ds = &tests.MockDataStore{}
|
||||
art = ds.Artwork().(*tests.MockArtworkRepo)
|
||||
queue = ds.ArtworkQueue().(*tests.MockArtworkQueueRepo)
|
||||
@ -969,9 +975,10 @@ var _ = Describe("refreshItems", func() {
|
||||
var queue *tests.MockArtworkQueueRepo
|
||||
var art *tests.MockArtworkRepo
|
||||
var out strings.Builder
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
albums := tests.CreateMockAlbumRepo()
|
||||
albums.SetData(model.Albums{{ID: "al-1"}, {ID: "al-3"}})
|
||||
ds = &tests.MockDataStore{MockedAlbum: albums}
|
||||
@ -1143,11 +1150,12 @@ var _ = Describe("cancelArtwork", func() {
|
||||
var ds *tests.MockDataStore
|
||||
var queue *tests.MockArtworkQueueRepo
|
||||
var out strings.Builder
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
accept := func(io.Writer, int64, int64) bool { return true }
|
||||
decline := func(io.Writer, int64, int64) bool { return false }
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
ds = &tests.MockDataStore{}
|
||||
queue = ds.ArtworkQueue().(*tests.MockArtworkQueueRepo)
|
||||
out.Reset()
|
||||
|
||||
@ -25,7 +25,7 @@ var _ = Describe("doctor", func() {
|
||||
// A file-backed DB so specs can corrupt raw pages; a table named like a real FTS
|
||||
// search table so IsFTSCorruptionOnly matches, plus a parent/child pair for FK checks.
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
dbPath = filepath.Join(GinkgoT().TempDir(), "doctor.db")
|
||||
reopen = func() {
|
||||
var err error
|
||||
|
||||
@ -65,16 +65,21 @@ var _ = Describe("formatPluginList", func() {
|
||||
})
|
||||
|
||||
var _ = Describe("enable/disable plugin", func() {
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
It("calls EnablePlugin on the manager", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
err := enablePlugin(context.Background(), mgr, "alpha")
|
||||
err := enablePlugin(ctx, mgr, "alpha")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.EnablePluginCalls).To(Equal([]string{"alpha"}))
|
||||
})
|
||||
|
||||
It("calls DisablePlugin on the manager", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
err := disablePlugin(context.Background(), mgr, "beta")
|
||||
err := disablePlugin(ctx, mgr, "beta")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.DisablePluginCalls).To(Equal([]string{"beta"}))
|
||||
})
|
||||
@ -82,14 +87,16 @@ var _ = Describe("enable/disable plugin", func() {
|
||||
|
||||
var _ = Describe("applyPluginEdit", func() {
|
||||
var cur *model.Plugin
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
cur = &model.Plugin{ID: "alpha", Users: `["bob"]`, Libraries: `[1,2]`, AllowWriteAccess: true}
|
||||
})
|
||||
|
||||
It("validates then updates config when config is provided", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
cfg := `{"key":"val"}`
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{config: &cfg})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{config: &cfg})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.ValidatePluginConfigCalls).To(HaveLen(1))
|
||||
Expect(mgr.ValidatePluginConfigCalls[0].ConfigJSON).To(Equal(cfg))
|
||||
@ -100,7 +107,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
It("updates users with allUsers flag", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
all := true
|
||||
err := applyPluginEdit(context.Background(), mgr, cur,
|
||||
err := applyPluginEdit(ctx, mgr, cur,
|
||||
pluginEditOptions{allUsers: &all})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginUsersCalls).To(HaveLen(1))
|
||||
@ -111,7 +118,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
all := true
|
||||
wr := true
|
||||
err := applyPluginEdit(context.Background(), mgr, cur,
|
||||
err := applyPluginEdit(ctx, mgr, cur,
|
||||
pluginEditOptions{allLibraries: &all, writeAccess: &wr})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginLibrariesCalls).To(HaveLen(1))
|
||||
@ -122,7 +129,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
It("preserves existing fields when only the write-access flag changes", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
no := false
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{writeAccess: &no})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{writeAccess: &no})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginLibrariesCalls).To(HaveLen(1))
|
||||
Expect(mgr.UpdatePluginLibrariesCalls[0].LibrariesJSON).To(Equal(`[1,2]`)) // not wiped
|
||||
@ -132,7 +139,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
It("preserves existing users when only the all-users flag changes", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
all := true
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{allUsers: &all})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{allUsers: &all})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginUsersCalls[0].UsersJSON).To(Equal(`["bob"]`)) // not wiped
|
||||
})
|
||||
@ -140,7 +147,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
It("parses a comma-separated users value into a JSON array", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
users := "alice, bob"
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{users: &users})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{users: &users})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginUsersCalls[0].UsersJSON).To(Equal(`["alice","bob"]`))
|
||||
})
|
||||
@ -148,7 +155,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
It("passes a JSON-array users value through unchanged", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
users := `["alice","bob"]`
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{users: &users})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{users: &users})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginUsersCalls[0].UsersJSON).To(Equal(`["alice","bob"]`))
|
||||
})
|
||||
@ -156,7 +163,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
It("rejects a malformed JSON-array users value", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
users := `["alice"`
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{users: &users})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{users: &users})
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginUsersCalls).To(BeEmpty())
|
||||
})
|
||||
@ -164,7 +171,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
It("parses a comma-separated libraries value into a JSON array of ints", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
libs := "1, 2"
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{libraries: &libs})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{libraries: &libs})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginLibrariesCalls[0].LibrariesJSON).To(Equal(`[1,2]`))
|
||||
})
|
||||
@ -172,7 +179,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
It("rejects a non-integer library ID", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
libs := "1,abc"
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{libraries: &libs})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{libraries: &libs})
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginLibrariesCalls).To(BeEmpty())
|
||||
})
|
||||
@ -181,7 +188,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
cur.AllUsers = true
|
||||
users := "alice"
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{users: &users})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{users: &users})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginUsersCalls[0].UsersJSON).To(Equal(`["alice"]`))
|
||||
Expect(mgr.UpdatePluginUsersCalls[0].AllUsers).To(BeFalse())
|
||||
@ -191,7 +198,7 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
cur.AllLibraries = true
|
||||
libs := "1"
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{libraries: &libs})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{libraries: &libs})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.UpdatePluginLibrariesCalls[0].LibrariesJSON).To(Equal(`[1]`))
|
||||
Expect(mgr.UpdatePluginLibrariesCalls[0].AllLibraries).To(BeFalse())
|
||||
@ -199,14 +206,14 @@ var _ = Describe("applyPluginEdit", func() {
|
||||
|
||||
It("does nothing and errors when no fields are set", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("aborts the config update when validation fails", func() {
|
||||
mgr := &tests.MockPluginManager{ValidateError: errors.New("bad config")}
|
||||
cfg := `{"key":"val"}`
|
||||
err := applyPluginEdit(context.Background(), mgr, cur, pluginEditOptions{config: &cfg})
|
||||
err := applyPluginEdit(ctx, mgr, cur, pluginEditOptions{config: &cfg})
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(mgr.ValidatePluginConfigCalls).To(HaveLen(1))
|
||||
Expect(mgr.UpdatePluginConfigCalls).To(BeEmpty())
|
||||
@ -353,7 +360,7 @@ var _ = Describe("formatManifestInfo enriched text", func() {
|
||||
var _ = Describe("rescanPlugins", func() {
|
||||
It("calls RescanPlugins on the manager", func() {
|
||||
mgr := &tests.MockPluginManager{}
|
||||
err := rescanPlugins(context.Background(), mgr)
|
||||
err := rescanPlugins(GinkgoT().Context(), mgr)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mgr.RescanPluginsCalls).To(Equal(1))
|
||||
})
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -18,7 +17,7 @@ var _ = Describe("trackScanInteractively", func() {
|
||||
progress <- &scanner.ProgressInfo{Error: "scan failed"}
|
||||
close(progress)
|
||||
|
||||
changesDetected, err := trackScanInteractively(context.Background(), progress)
|
||||
changesDetected, err := trackScanInteractively(GinkgoT().Context(), progress)
|
||||
Expect(changesDetected).To(BeTrue())
|
||||
Expect(err).To(MatchError("scan failed"))
|
||||
})
|
||||
|
||||
@ -207,8 +207,8 @@ type TagConf struct {
|
||||
|
||||
type lastfmOptions struct {
|
||||
Enabled bool
|
||||
ApiKey string //nolint:gosec
|
||||
Secret string //nolint:gosec
|
||||
ApiKey string
|
||||
Secret string
|
||||
Language string
|
||||
ScrobbleFirstArtistOnly bool
|
||||
MinScrobbleDuration time.Duration
|
||||
@ -253,7 +253,7 @@ type httpHeaderOptions struct {
|
||||
type prometheusOptions struct {
|
||||
Enabled bool
|
||||
MetricsPath string
|
||||
Password string //nolint:gosec
|
||||
Password string
|
||||
}
|
||||
|
||||
type AudioDeviceDefinition []string
|
||||
|
||||
@ -55,10 +55,12 @@ var _ ArtistMBIDRetriever = (*MockAgent)(nil)
|
||||
var _ PluginLoader = (*MockPluginLoader)(nil)
|
||||
|
||||
var _ = Describe("Agents with Plugin Loading", func() {
|
||||
var ctx context.Context
|
||||
var mockLoader *MockPluginLoader
|
||||
var agents *Agents
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
mockLoader = NewMockPluginLoader()
|
||||
|
||||
// Create the agents instance with our mock loader
|
||||
@ -144,8 +146,6 @@ var _ = Describe("Agents with Plugin Loading", func() {
|
||||
})
|
||||
|
||||
It("should load plugin agents on demand", func() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Configure to use our plugin
|
||||
conf.Update(func(c *conf.Options) { c.Agents = "plugin_agent" })
|
||||
|
||||
@ -236,8 +236,6 @@ var _ = Describe("Agents with Plugin Loading", func() {
|
||||
})
|
||||
|
||||
It("should NOT call LoadMediaAgent for built-in agents", func() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Create a mock built-in agent
|
||||
Register("builtin_agent", func(ds model.DataStore) Interface {
|
||||
return &MockAgent{
|
||||
@ -263,8 +261,6 @@ var _ = Describe("Agents with Plugin Loading", func() {
|
||||
})
|
||||
|
||||
It("should NOT call LoadMediaAgent for invalid agent names", func() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Configure with an invalid agent name (not built-in, not a plugin)
|
||||
conf.Update(func(c *conf.Options) { c.Agents = "invalid_agent" })
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ var _ = Describe("Agents", func() {
|
||||
var ds model.DataStore
|
||||
var mfRepo *tests.MockMediaFileRepo
|
||||
BeforeEach(func() {
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
ctx, cancel = context.WithCancel(GinkgoT().Context())
|
||||
mfRepo = tests.CreateMockMediaFileRepo()
|
||||
ds = &tests.MockDataStore{MockedMediaFile: mfRepo}
|
||||
})
|
||||
|
||||
@ -17,7 +17,7 @@ var _ = Describe("localAgent GetSimilarSongsByTrack", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
mfRepo = &tests.MockMediaFileRepo{}
|
||||
ds = &tests.MockDataStore{MockedMediaFile: mfRepo}
|
||||
agent = &localAgent{ds: ds}
|
||||
|
||||
@ -11,11 +11,15 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("SessionKeys", func() {
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
user := model.User{ID: "u-1"}
|
||||
ds := &tests.MockDataStore{MockedUserProps: &tests.MockedUserPropsRepo{}}
|
||||
sk := SessionKeys{DataStore: ds, KeyName: "fakeSessionKey"}
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
It("uses the assigned key name", func() {
|
||||
Expect(sk.KeyName).To(Equal("fakeSessionKey"))
|
||||
})
|
||||
|
||||
@ -23,6 +23,7 @@ import (
|
||||
|
||||
var _ = Describe("Archiver", func() {
|
||||
var (
|
||||
ctx context.Context
|
||||
arch core.Archiver
|
||||
ms *mockMediaStreamer
|
||||
dc *fakeDecider
|
||||
@ -32,6 +33,7 @@ var _ = Describe("Archiver", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
ms = &mockMediaStreamer{}
|
||||
dc = &fakeDecider{}
|
||||
sh = &mockShare{}
|
||||
@ -57,7 +59,7 @@ var _ = Describe("Archiver", func() {
|
||||
ms.On("NewStream", mock.Anything, mock.Anything, stream.Request{Format: "mp3", BitRate: 128}).Return(io.NopCloser(strings.NewReader("test")), nil).Times(3)
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
err := arch.ZipAlbum(context.Background(), "1", "mp3", 128, out)
|
||||
err := arch.ZipAlbum(ctx, "1", "mp3", 128, out)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
zr, err := zip.NewReader(bytes.NewReader(out.Bytes()), int64(out.Len()))
|
||||
@ -106,7 +108,7 @@ var _ = Describe("Archiver", func() {
|
||||
ms.On("NewStream", mock.Anything, mock.Anything, stream.Request{Format: "mp3", BitRate: 128}).Return(io.NopCloser(strings.NewReader("test")), nil).Times(2)
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
err := arch.ZipArtist(context.Background(), "1", "mp3", 128, out)
|
||||
err := arch.ZipArtist(ctx, "1", "mp3", 128, out)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
zr, err := zip.NewReader(bytes.NewReader(out.Bytes()), int64(out.Len()))
|
||||
@ -127,7 +129,7 @@ var _ = Describe("Archiver", func() {
|
||||
ms.On("NewStream", mock.Anything, mock.Anything, mock.Anything).Return(io.NopCloser(strings.NewReader("test")), nil)
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
Expect(arch.ZipArtist(context.Background(), "1", "mp3", 128, out)).To(Succeed())
|
||||
Expect(arch.ZipArtist(ctx, "1", "mp3", 128, out)).To(Succeed())
|
||||
zr, err := zip.NewReader(bytes.NewReader(out.Bytes()), int64(out.Len()))
|
||||
Expect(err).To(BeNil())
|
||||
names := make([]string, len(zr.File))
|
||||
@ -267,7 +269,7 @@ var _ = Describe("Archiver", func() {
|
||||
Return(nil, stream.ErrTooManyTranscodes).Once()
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
err := arch.ZipAlbum(context.Background(), "1", "mp3", 128, out)
|
||||
err := arch.ZipAlbum(ctx, "1", "mp3", 128, out)
|
||||
Expect(err).To(MatchError(stream.ErrTooManyTranscodes))
|
||||
// NewStream should only have been called once: the loop must bail
|
||||
// out on the rejection instead of trying every remaining track.
|
||||
@ -293,7 +295,7 @@ var _ = Describe("Archiver", func() {
|
||||
ms.On("NewStream", mock.Anything, mock.Anything, stream.Request{Format: "mp3", BitRate: 128}).Return(io.NopCloser(strings.NewReader("test")), nil).Times(2)
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
err := arch.ZipShare(context.Background(), share, out)
|
||||
err := arch.ZipShare(ctx, share, out)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
// Share.Load records a visit; re-loading here would double-count
|
||||
@ -353,7 +355,7 @@ var _ = Describe("Archiver", func() {
|
||||
ms.On("NewStream", mock.Anything, mock.Anything, stream.Request{Format: "mp3", BitRate: 128}).Return(io.NopCloser(strings.NewReader("test")), nil).Times(2)
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
err := arch.ZipPlaylist(context.Background(), "1", "mp3", 128, out)
|
||||
err := arch.ZipPlaylist(ctx, "1", "mp3", 128, out)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
zr, err := zip.NewReader(bytes.NewReader(out.Bytes()), int64(out.Len()))
|
||||
@ -396,7 +398,7 @@ var _ = Describe("Archiver", func() {
|
||||
})
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
Expect(arch.ZipAlbum(context.Background(), "1", "mp3", 128, out)).To(Succeed())
|
||||
Expect(arch.ZipAlbum(ctx, "1", "mp3", 128, out)).To(Succeed())
|
||||
|
||||
files := readZip(out)
|
||||
Expect(files).To(HaveLen(2))
|
||||
@ -417,7 +419,7 @@ var _ = Describe("Archiver", func() {
|
||||
})
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
Expect(arch.ZipArtist(context.Background(), "1", "mp3", 128, out)).To(Succeed())
|
||||
Expect(arch.ZipArtist(ctx, "1", "mp3", 128, out)).To(Succeed())
|
||||
|
||||
files := readZip(out)
|
||||
Expect(files).To(HaveLen(5))
|
||||
@ -438,7 +440,7 @@ var _ = Describe("Archiver", func() {
|
||||
})
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
Expect(arch.ZipArtist(context.Background(), "1", "mp3", 128, out)).To(Succeed())
|
||||
Expect(arch.ZipArtist(ctx, "1", "mp3", 128, out)).To(Succeed())
|
||||
|
||||
files := readZip(out)
|
||||
Expect(files).To(HaveKeyWithValue("Greatest Hits [2001]/folder.jpg", jpegData))
|
||||
@ -459,7 +461,7 @@ var _ = Describe("Archiver", func() {
|
||||
ms.On("NewStream", mock.Anything, mock.Anything, mock.Anything).Return(io.NopCloser(strings.NewReader("test")), nil)
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
Expect(arch.ZipPlaylist(context.Background(), "1", "mp3", 128, out)).To(Succeed())
|
||||
Expect(arch.ZipPlaylist(ctx, "1", "mp3", 128, out)).To(Succeed())
|
||||
|
||||
files := readZip(out)
|
||||
Expect(files).To(HaveLen(3))
|
||||
@ -483,7 +485,7 @@ var _ = Describe("Archiver", func() {
|
||||
}
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
Expect(arch.ZipShare(context.Background(), share, out)).To(Succeed())
|
||||
Expect(arch.ZipShare(ctx, share, out)).To(Succeed())
|
||||
|
||||
files := readZip(out)
|
||||
Expect(files).To(HaveLen(2))
|
||||
@ -498,7 +500,7 @@ var _ = Describe("Archiver", func() {
|
||||
})
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
Expect(arch.ZipAlbum(context.Background(), "1", "mp3", 128, out)).To(Succeed())
|
||||
Expect(arch.ZipAlbum(ctx, "1", "mp3", 128, out)).To(Succeed())
|
||||
|
||||
files := readZip(out)
|
||||
Expect(files).To(HaveLen(1))
|
||||
|
||||
@ -75,7 +75,7 @@ var _ = Describe("agent images", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = w.Write([]byte("image-bytes"))
|
||||
}))
|
||||
|
||||
@ -70,7 +70,7 @@ var _ = Describe("Artwork", func() {
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
var err error
|
||||
repoRoot, err = os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -529,7 +529,7 @@ var _ = Describe("EntityExists", func() {
|
||||
var ds *tests.MockDataStore
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
albumRepo := tests.CreateMockAlbumRepo()
|
||||
albumRepo.SetData(model.Albums{{ID: "al1"}})
|
||||
artistRepo := tests.CreateMockArtistRepo()
|
||||
|
||||
@ -13,6 +13,12 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Disc Artwork Reader", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
Describe("extractDiscNumber", func() {
|
||||
DescribeTable("extracts disc number from filename based on glob pattern",
|
||||
func(pattern, filename string, expectedNum int, expectedOk bool) {
|
||||
@ -66,13 +72,9 @@ var _ = Describe("Disc Artwork Reader", func() {
|
||||
})
|
||||
|
||||
Describe("fromExternalFile", func() {
|
||||
var (
|
||||
ctx context.Context
|
||||
tmpDir string
|
||||
)
|
||||
var tmpDir string
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
tmpDir = GinkgoT().TempDir()
|
||||
})
|
||||
|
||||
@ -349,13 +351,9 @@ var _ = Describe("Disc Artwork Reader", func() {
|
||||
})
|
||||
|
||||
Describe("fromDiscSubtitle", func() {
|
||||
var (
|
||||
ctx context.Context
|
||||
tmpDir string
|
||||
)
|
||||
var tmpDir string
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
tmpDir = GinkgoT().TempDir()
|
||||
})
|
||||
|
||||
@ -453,10 +451,10 @@ var _ = Describe("Disc Artwork Reader", func() {
|
||||
|
||||
Describe("selectImage", func() {
|
||||
It("abandons the walk when the context is cancelled", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancelled, cancel := context.WithCancel(ctx)
|
||||
cancel()
|
||||
|
||||
res, err := reader.selectImage(ctx, nil, "disc*.*, cover.*", &chainState{})
|
||||
res, err := reader.selectImage(cancelled, nil, "disc*.*, cover.*", &chainState{})
|
||||
|
||||
Expect(err).To(MatchError(context.Canceled))
|
||||
Expect(res.reader).To(BeNil())
|
||||
@ -470,7 +468,7 @@ var _ = Describe("Disc Artwork Reader", func() {
|
||||
Expect(os.MkdirAll(filepath.Dir(track), 0755)).To(Succeed())
|
||||
Expect(os.WriteFile(track, []byte("not audio"), 0600)).To(Succeed())
|
||||
|
||||
res, err := reader.selectImage(context.Background(), tests.NewMockFFmpeg(""), "embedded",
|
||||
res, err := reader.selectImage(ctx, tests.NewMockFFmpeg(""), "embedded",
|
||||
&chainState{trace: trace})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -482,7 +480,7 @@ var _ = Describe("Disc Artwork Reader", func() {
|
||||
trace := &ChainTrace{}
|
||||
reader.firstTrackRel = ""
|
||||
|
||||
res, err := reader.selectImage(context.Background(), tests.NewMockFFmpeg(""), "embedded",
|
||||
res, err := reader.selectImage(ctx, tests.NewMockFFmpeg(""), "embedded",
|
||||
&chainState{trace: trace})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -493,19 +491,19 @@ var _ = Describe("Disc Artwork Reader", func() {
|
||||
|
||||
Describe("discCandidates", func() {
|
||||
It("returns a resolvable candidate for glob patterns", func() {
|
||||
cc := reader.discCandidates(context.Background(), nil, "disc*.*")
|
||||
cc := reader.discCandidates(ctx, nil, "disc*.*")
|
||||
Expect(cc).To(HaveLen(1))
|
||||
Expect(cc[0].resolve).ToNot(BeNil())
|
||||
})
|
||||
|
||||
It("returns one candidate per entry, in order", func() {
|
||||
cc := reader.discCandidates(context.Background(), nil, "disc*.*, cd*.*, embedded")
|
||||
cc := reader.discCandidates(ctx, nil, "disc*.*, cd*.*, embedded")
|
||||
Expect(slice.Map(cc, func(c discCandidate) string { return c.pattern })).
|
||||
To(Equal([]string{"disc*.*", "cd*.*", "embedded"}))
|
||||
})
|
||||
|
||||
It("skips an empty entry rather than building a glob that matches nothing", func() {
|
||||
cc := reader.discCandidates(context.Background(), nil, "disc*.*,")
|
||||
cc := reader.discCandidates(ctx, nil, "disc*.*,")
|
||||
Expect(cc).To(HaveLen(1))
|
||||
})
|
||||
|
||||
@ -514,7 +512,7 @@ var _ = Describe("Disc Artwork Reader", func() {
|
||||
DescribeTable("keeps an entry that maps to no source, with its reason",
|
||||
func(setup func(), priority, reason string) {
|
||||
setup()
|
||||
cc := reader.discCandidates(context.Background(), nil, priority)
|
||||
cc := reader.discCandidates(ctx, nil, priority)
|
||||
Expect(cc).To(HaveLen(1))
|
||||
Expect(cc[0].resolve).To(BeNil())
|
||||
Expect(cc[0].skip).To(Equal(reason))
|
||||
@ -530,7 +528,7 @@ var _ = Describe("Disc Artwork Reader", func() {
|
||||
|
||||
It("returns source func for discsubtitle pattern", func() {
|
||||
reader.album = model.Album{Discs: model.Discs{2: "Bonus Tracks"}}
|
||||
cc := reader.discCandidates(context.Background(), nil, "discsubtitle")
|
||||
cc := reader.discCandidates(ctx, nil, "discsubtitle")
|
||||
Expect(cc).To(HaveLen(1))
|
||||
Expect(cc[0].resolve).ToNot(BeNil())
|
||||
})
|
||||
|
||||
@ -63,7 +63,7 @@ var _ = Describe("Acquisition → serve loop", func() {
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
repoRoot, err := os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
coverBytes = readFixture(coverFixture)
|
||||
|
||||
@ -71,13 +71,13 @@ var _ = BeforeSuite(func() {
|
||||
c.DataFolder = conf.NewDir(GinkgoT().TempDir())
|
||||
})
|
||||
db.Db().SetMaxOpenConns(1)
|
||||
db.Init(request.WithUser(context.Background(), model.User{ID: "admin-1", IsAdmin: true}))
|
||||
db.Init(request.WithUser(GinkgoT().Context(), model.User{ID: "admin-1", IsAdmin: true}))
|
||||
|
||||
userTables = harness.ResettableTables()
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
db.Close(context.Background())
|
||||
db.Close(GinkgoT().Context())
|
||||
})
|
||||
|
||||
func setupResolutionHarness() {
|
||||
|
||||
@ -23,7 +23,7 @@ var _ = Describe("loadAlbumFoldersPaths", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
now = time.Now().Truncate(time.Second)
|
||||
repo = &fakeFolderRepo{}
|
||||
ds = &tests.MockDataStore{MockedFolder: repo}
|
||||
|
||||
@ -45,7 +45,7 @@ var _ = Describe("loadArtistFolder", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
updatedAt = time.Now().Truncate(time.Second).Add(5 * time.Minute)
|
||||
repo = &fakeFolderRepo{result: []model.Folder{{ImagesUpdatedAt: updatedAt}}}
|
||||
libRepo := &tests.MockLibraryRepo{}
|
||||
|
||||
@ -21,7 +21,7 @@ var _ = Describe("findImageInFolder", func() {
|
||||
var files fstest.MapFS
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
files = fstest.MapFS{"artist.jpg": &fstest.MapFile{Data: []byte("img")}}
|
||||
})
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ var _ = Describe("Housekeeping", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
conf.Update(func(c *conf.Options) {
|
||||
c.CoverArtPriority = "embedded, folder"
|
||||
c.ArtistArtPriority = "artist.jpg"
|
||||
@ -150,7 +150,7 @@ var _ = Describe("ItemName", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
albumRepo := tests.CreateMockAlbumRepo()
|
||||
albumRepo.SetData(model.Albums{
|
||||
{ID: "al-1", Name: "Kid A"},
|
||||
|
||||
@ -11,6 +11,12 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("resizedItem", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
Describe("Reader", func() {
|
||||
newItem := func(open func() (io.ReadCloser, error)) *resizedItem {
|
||||
return &resizedItem{hash: "abc123", size: 300, open: open}
|
||||
@ -19,20 +25,20 @@ var _ = Describe("resizedItem", func() {
|
||||
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())
|
||||
_, err := newItem(func() (io.ReadCloser, error) { return nil, nil }).Reader(ctx)
|
||||
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())
|
||||
_, err := newItem(func() (io.ReadCloser, error) { return nil, boom }).Reader(ctx)
|
||||
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())
|
||||
}).Reader(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer rc.Close()
|
||||
Expect(io.ReadAll(rc)).To(Equal([]byte("not an image")))
|
||||
|
||||
@ -19,9 +19,9 @@ var _ = Describe("ImageStore", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
root = GinkgoT().TempDir()
|
||||
store = NewImageStore(root)
|
||||
ctx = context.Background()
|
||||
})
|
||||
|
||||
It("hashes deterministically", func() {
|
||||
|
||||
@ -56,7 +56,7 @@ var _ = Describe("processor.acquire", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
var err error
|
||||
repoRoot, err = os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -51,7 +51,7 @@ var _ = Describe("Prune", func() {
|
||||
"ar": {"live-artist": true},
|
||||
}
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).To(Succeed())
|
||||
Expect(prune(ctx, ds, store)).To(Succeed())
|
||||
|
||||
_, err := awRepo.GetItemArtwork(ctx, model.KindAlbumArtwork, "gone-album", model.ImageTypePrimary)
|
||||
Expect(err).To(MatchError(model.ErrNotFound))
|
||||
@ -70,7 +70,7 @@ var _ = Describe("Prune", func() {
|
||||
queueRepo.ExistingIDs = map[string]map[string]bool{"al": {"live-album": true}}
|
||||
ds.MockedArtworkQueue = queueRepo
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).To(Succeed())
|
||||
Expect(prune(ctx, ds, store)).To(Succeed())
|
||||
|
||||
Expect(findQueued(queueRepo, "al", "gone-album")).To(BeNil())
|
||||
Expect(findQueued(queueRepo, "al", "live-album")).ToNot(BeNil())
|
||||
@ -90,7 +90,7 @@ var _ = Describe("Prune", func() {
|
||||
Expect(store.Write(hk, "image/jpeg", bytes.NewReader(kept))).To(Succeed())
|
||||
Expect(awRepo.PutImage(ctx, &model.Artwork{Hash: hk, Mime: "image/jpeg"})).To(Succeed())
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).To(Succeed())
|
||||
Expect(prune(ctx, ds, store)).To(Succeed())
|
||||
|
||||
_, err := awRepo.GetImage(ctx, h)
|
||||
Expect(err).To(MatchError(model.ErrNotFound))
|
||||
@ -110,7 +110,7 @@ var _ = Describe("Prune", func() {
|
||||
Expect(awRepo.PutItemArtwork(ctx, &model.ItemArtwork{ItemKind: "al", ItemID: "a1",
|
||||
ImageType: model.ImageTypePrimary, Hash: h, Source: "folder"})).To(Succeed())
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).To(Succeed())
|
||||
Expect(prune(ctx, ds, store)).To(Succeed())
|
||||
|
||||
_, err := awRepo.GetImage(ctx, h)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -126,7 +126,7 @@ var _ = Describe("Prune", func() {
|
||||
// Reacquisition refreshed created_at, so the row is unreferenced but too young to drop.
|
||||
Expect(awRepo.PutImage(ctx, &model.Artwork{Hash: h, Mime: "image/jpeg"})).To(Succeed())
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).To(Succeed())
|
||||
Expect(prune(ctx, ds, store)).To(Succeed())
|
||||
|
||||
_, err := awRepo.GetImage(ctx, h)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -143,7 +143,7 @@ var _ = Describe("Prune", func() {
|
||||
ageArtwork(h, time.Now().Add(-2*time.Hour))
|
||||
// The row is orphaned, but a concurrent acquisition just touched the file's mtime.
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).To(Succeed())
|
||||
Expect(prune(ctx, ds, store)).To(Succeed())
|
||||
|
||||
rc, err := store.Open(h, "image/jpeg")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -157,7 +157,7 @@ var _ = Describe("Prune", func() {
|
||||
old := time.Now().Add(-2 * time.Hour)
|
||||
Expect(os.Chtimes(store.path(h, "image/jpeg"), old, old)).To(Succeed())
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).To(Succeed())
|
||||
Expect(prune(ctx, ds, store)).To(Succeed())
|
||||
|
||||
_, err := store.Open(h, "image/jpeg")
|
||||
Expect(os.IsNotExist(err)).To(BeTrue())
|
||||
@ -174,7 +174,7 @@ var _ = Describe("Prune", func() {
|
||||
// The row records the current mime; the .png file is a superseded variant.
|
||||
Expect(awRepo.PutImage(ctx, &model.Artwork{Hash: h, Mime: "image/jpeg"})).To(Succeed())
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).To(Succeed())
|
||||
Expect(prune(ctx, ds, store)).To(Succeed())
|
||||
|
||||
_, err := store.Open(h, "image/png")
|
||||
Expect(os.IsNotExist(err)).To(BeTrue())
|
||||
@ -210,7 +210,7 @@ var _ = Describe("Prune", func() {
|
||||
Expect(os.Chmod(shardDir, 0500)).To(Succeed())
|
||||
DeferCleanup(func() { _ = os.Chmod(shardDir, 0755) })
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).To(Succeed())
|
||||
Expect(prune(ctx, ds, store)).To(Succeed())
|
||||
|
||||
_, err := awRepo.GetImage(ctx, hg)
|
||||
Expect(err).To(MatchError(model.ErrNotFound))
|
||||
@ -232,7 +232,7 @@ var _ = Describe("Prune", func() {
|
||||
h, _ := hashImage(bytes.NewReader(data))
|
||||
Expect(store.Write(h, "image/jpeg", bytes.NewReader(data))).To(Succeed())
|
||||
|
||||
Expect(prune(context.Background(), ds, store)).ToNot(Succeed())
|
||||
Expect(prune(ctx, ds, store)).ToNot(Succeed())
|
||||
|
||||
rc, err := store.Open(h, "image/jpeg")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -54,7 +54,7 @@ var _ = Describe("resolveItem", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
var err error
|
||||
repoRoot, err = os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -81,13 +81,19 @@ var _ = Describe("encodeSteps/DecodeTrace", func() {
|
||||
})
|
||||
|
||||
var _ = Describe("chainTrace", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
It("returns nil when no trace is attached", func() {
|
||||
Expect(traceFrom(context.Background())).To(BeNil())
|
||||
Expect(traceFrom(ctx)).To(BeNil())
|
||||
})
|
||||
|
||||
It("collects steps in order", func() {
|
||||
t := &ChainTrace{}
|
||||
ctx := withTrace(context.Background(), t)
|
||||
ctx = withTrace(ctx, t)
|
||||
|
||||
traceFrom(ctx).add(TraceStep{Candidate: "cover.*", Outcome: OutcomeMiss})
|
||||
traceFrom(ctx).add(TraceStep{Candidate: "embedded", Outcome: OutcomeHit, Detail: "/music/a.flac"})
|
||||
@ -170,7 +176,7 @@ var _ = Describe("external agent tracing", func() {
|
||||
)
|
||||
BeforeEach(func() {
|
||||
t = &ChainTrace{}
|
||||
ctx = withTrace(context.Background(), t)
|
||||
ctx = withTrace(GinkgoT().Context(), t)
|
||||
body = io.NopCloser(strings.NewReader("x"))
|
||||
})
|
||||
|
||||
@ -226,7 +232,7 @@ var _ = Describe("resolveAlbum tracing", func() {
|
||||
ffm = tests.NewMockFFmpeg("")
|
||||
ag = agents.GetAgents(&tests.MockDataStore{}, nil)
|
||||
t = &ChainTrace{}
|
||||
ctx = withTrace(context.Background(), t)
|
||||
ctx = withTrace(GinkgoT().Context(), t)
|
||||
})
|
||||
|
||||
It("records a pattern skipped because the album folder holds no images", func() {
|
||||
@ -317,7 +323,7 @@ var _ = Describe("resolveArtist tracing", func() {
|
||||
ffm = tests.NewMockFFmpeg("")
|
||||
ag = agents.GetAgents(&tests.MockDataStore{}, nil)
|
||||
t = &ChainTrace{}
|
||||
ctx = withTrace(context.Background(), t)
|
||||
ctx = withTrace(GinkgoT().Context(), t)
|
||||
})
|
||||
|
||||
It("records the upload short-circuit as a hit", func() {
|
||||
@ -402,6 +408,7 @@ var _ = Describe("resolveArtist tracing", func() {
|
||||
|
||||
var _ = Describe("NewTracingResolver", func() {
|
||||
var (
|
||||
ctx context.Context
|
||||
ds *tests.MockDataStore
|
||||
albumRepo *tests.MockAlbumRepo
|
||||
artistRepo *tests.MockArtistRepo
|
||||
@ -412,6 +419,7 @@ var _ = Describe("NewTracingResolver", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
conf.Update(func(c *conf.Options) {
|
||||
c.DataFolder = conf.NewDir(GinkgoT().TempDir())
|
||||
c.CoverArtPriority = "external, embedded"
|
||||
@ -450,7 +458,7 @@ var _ = Describe("NewTracingResolver", func() {
|
||||
})
|
||||
|
||||
It("asks the agents and records what each answered", func() {
|
||||
source, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(context.Background(), model.KindAlbumArtwork, "al1")
|
||||
source, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(ctx, model.KindAlbumArtwork, "al1")
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(source).To(Equal("embedded"))
|
||||
@ -459,7 +467,7 @@ var _ = Describe("NewTracingResolver", func() {
|
||||
})
|
||||
|
||||
It("records the local chain steps too", func() {
|
||||
_, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(context.Background(), model.KindAlbumArtwork, "al1")
|
||||
_, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(ctx, model.KindAlbumArtwork, "al1")
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
last := t.Steps()[len(t.Steps())-1]
|
||||
@ -468,7 +476,7 @@ var _ = Describe("NewTracingResolver", func() {
|
||||
})
|
||||
|
||||
It("never persists artwork state", func() {
|
||||
_, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(context.Background(), model.KindAlbumArtwork, "al1")
|
||||
_, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(ctx, model.KindAlbumArtwork, "al1")
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(artworkRepo.ItemData).To(BeEmpty(),
|
||||
@ -477,7 +485,7 @@ var _ = Describe("NewTracingResolver", func() {
|
||||
})
|
||||
|
||||
It("resolves an artist without persisting anything", func() {
|
||||
source, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(context.Background(), model.KindArtistArtwork, "ar1")
|
||||
source, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(ctx, model.KindArtistArtwork, "ar1")
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(source).To(BeEmpty())
|
||||
@ -493,7 +501,7 @@ var _ = Describe("NewTracingResolver", func() {
|
||||
ID: "al2", Name: "Album", EmbedArtPath: "tests/fixtures/artist/an-album/no-such-file.mp3", FolderIDs: []string{"f1"},
|
||||
}})
|
||||
|
||||
source, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(context.Background(), model.KindAlbumArtwork, "al2")
|
||||
source, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(ctx, model.KindAlbumArtwork, "al2")
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(source).To(Equal("embedded"))
|
||||
@ -514,9 +522,9 @@ var _ = Describe("NewTracingResolver", func() {
|
||||
ds.MockedMediaFile = mfRepo
|
||||
offline := NewTracingResolver(ds, imageAgents(fake), ffm, t, false)
|
||||
|
||||
_, err := offline.Resolve(context.Background(), model.KindDiscArtwork, "al1:1")
|
||||
_, err := offline.Resolve(ctx, model.KindDiscArtwork, "al1:1")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = offline.Resolve(context.Background(), model.KindMediaFileArtwork, "mf1")
|
||||
_, err = offline.Resolve(ctx, model.KindMediaFileArtwork, "mf1")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(fake.albumCalls).To(BeZero())
|
||||
@ -524,7 +532,7 @@ var _ = Describe("NewTracingResolver", func() {
|
||||
})
|
||||
|
||||
It("propagates a lookup error", func() {
|
||||
_, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(context.Background(), model.KindAlbumArtwork, "nope")
|
||||
_, err := NewTracingResolver(ds, imageAgents(fake), ffm, t, true).Resolve(ctx, model.KindAlbumArtwork, "nope")
|
||||
Expect(err).To(MatchError(model.ErrNotFound))
|
||||
})
|
||||
})
|
||||
@ -558,7 +566,7 @@ var _ = Describe("resolveDisc tracing", func() {
|
||||
}
|
||||
ffm = tests.NewMockFFmpeg("")
|
||||
t = &ChainTrace{}
|
||||
ctx = withTrace(context.Background(), t)
|
||||
ctx = withTrace(GinkgoT().Context(), t)
|
||||
})
|
||||
|
||||
It("accounts for every configured entry, including the ones that map to no source", func() {
|
||||
@ -626,7 +634,7 @@ var _ = Describe("resolveMediaFile tracing", func() {
|
||||
ds = &tests.MockDataStore{MockedMediaFile: mfRepo, MockedLibrary: libRepo}
|
||||
ffm = tests.NewMockFFmpeg("")
|
||||
t = &ChainTrace{}
|
||||
ctx = withTrace(context.Background(), t)
|
||||
ctx = withTrace(GinkgoT().Context(), t)
|
||||
})
|
||||
|
||||
It("separates a disabled setting from a track with nothing embedded", func() {
|
||||
|
||||
@ -109,7 +109,7 @@ var _ = Describe("Uploader", func() {
|
||||
})
|
||||
|
||||
It("is a no-op for an unknown entity type", func() {
|
||||
svc.EnqueueArtwork(context.Background(), "unknown", "x-1")
|
||||
svc.EnqueueArtwork(ctx, "unknown", "x-1")
|
||||
Expect(queueRepo.DequeueBatch(ctx, 1000)).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
|
||||
@ -99,7 +99,7 @@ var _ = Describe("Worker soak", func() {
|
||||
start := time.Now()
|
||||
for i := range soakCycles {
|
||||
it := items[i%len(items)]
|
||||
out, _, _ := proc.acquire(context.Background(), it)
|
||||
out, _, _ := proc.acquire(ctx, it)
|
||||
|
||||
// Read-back exercises the surfaces a caller would use after acquisition.
|
||||
if out == outcomeFound {
|
||||
|
||||
@ -13,14 +13,18 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("common.go", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
Describe("userName", func() {
|
||||
It("returns the username from context", func() {
|
||||
ctx := request.WithUser(context.Background(), model.User{UserName: "testuser"})
|
||||
Expect(userName(ctx)).To(Equal("testuser"))
|
||||
Expect(userName(request.WithUser(ctx, model.User{UserName: "testuser"}))).To(Equal("testuser"))
|
||||
})
|
||||
|
||||
It("returns 'UNKNOWN' if no user in context", func() {
|
||||
ctx := context.Background()
|
||||
Expect(userName(ctx)).To(Equal("UNKNOWN"))
|
||||
})
|
||||
})
|
||||
@ -42,13 +46,11 @@ var _ = Describe("common.go", func() {
|
||||
})
|
||||
|
||||
It("returns the absolute path when library exists", func() {
|
||||
ctx := context.Background()
|
||||
abs := AbsolutePath(ctx, ds, libId, path)
|
||||
Expect(abs).To(Equal(filepath.FromSlash("/library/root/music/file.mp3")))
|
||||
})
|
||||
|
||||
It("returns the original path if library not found", func() {
|
||||
ctx := context.Background()
|
||||
abs := AbsolutePath(ctx, ds, 999, path)
|
||||
Expect(abs).To(Equal(path))
|
||||
})
|
||||
|
||||
@ -34,7 +34,7 @@ var _ = Describe("Library Service", func() {
|
||||
var pluginManager *mockPluginUnloader
|
||||
|
||||
BeforeEach(func() {
|
||||
|
||||
ctx = GinkgoT().Context()
|
||||
ds = &tests.MockDataStore{}
|
||||
libraryRepo = &tests.MockLibraryRepo{}
|
||||
userRepo = tests.CreateMockUserRepo()
|
||||
@ -52,7 +52,6 @@ var _ = Describe("Library Service", func() {
|
||||
// Create a mock plugin unloader
|
||||
pluginManager = &mockPluginUnloader{}
|
||||
service = core.NewLibrary(ds, scanner, watcherManager, broker, pluginManager)
|
||||
ctx = context.Background()
|
||||
|
||||
// Create a temporary directory for testing valid paths
|
||||
var err error
|
||||
|
||||
@ -21,7 +21,7 @@ var _ = Describe("Maintenance", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
ctx = request.WithUser(ctx, model.User{ID: "user1", IsAdmin: true})
|
||||
|
||||
ds = createTestDataStore()
|
||||
|
||||
@ -109,7 +109,7 @@ func (c *insightsCollector) sendInsights(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := hc.Do(req) //nolint:gosec
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
log.Trace(ctx, "Could not send Insights data", err)
|
||||
return
|
||||
|
||||
@ -20,11 +20,13 @@ import (
|
||||
|
||||
var _ = Describe("MPV", func() {
|
||||
var (
|
||||
ctx context.Context
|
||||
testScript string
|
||||
tempDir string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
|
||||
// Reset MPV cache
|
||||
mpvOnce = sync.Once{}
|
||||
@ -213,7 +215,7 @@ var _ = Describe("MPV", func() {
|
||||
|
||||
It("executes MPV command and captures arguments correctly", func() {
|
||||
tests.SkipOnWindows("mpv binary not available in CI (#TBD-mpv-windows)")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
deviceName := "auto"
|
||||
@ -241,7 +243,7 @@ var _ = Describe("MPV", func() {
|
||||
|
||||
It("handles file paths with spaces", func() {
|
||||
tests.SkipOnWindows("mpv binary not available in CI (#TBD-mpv-windows)")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
deviceName := "auto"
|
||||
@ -271,7 +273,7 @@ var _ = Describe("MPV", func() {
|
||||
|
||||
It("passes all snapcast arguments correctly", func() {
|
||||
tests.SkipOnWindows("mpv binary not available in CI (#TBD-mpv-windows)")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
deviceName := "auto"
|
||||
@ -304,7 +306,7 @@ var _ = Describe("MPV", func() {
|
||||
|
||||
Context("with nil args", func() {
|
||||
It("returns error when args is nil", func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
||||
defer cancel()
|
||||
|
||||
_, err := start(ctx, nil)
|
||||
@ -313,7 +315,7 @@ var _ = Describe("MPV", func() {
|
||||
})
|
||||
|
||||
It("returns error when args is empty", func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
||||
defer cancel()
|
||||
|
||||
_, err := start(ctx, []string{})
|
||||
@ -361,7 +363,7 @@ var _ = Describe("MPV", func() {
|
||||
})
|
||||
|
||||
It("returns error when createMPVCommand fails", func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
||||
defer cancel()
|
||||
|
||||
playbackDone := make(chan bool, 1)
|
||||
@ -400,7 +402,7 @@ done
|
||||
}
|
||||
|
||||
scriptPath := filepath.Join(tempDir, "mock_mpv"+scriptExt)
|
||||
err := os.WriteFile(scriptPath, []byte(scriptContent), 0755) // nolint:gosec
|
||||
err := os.WriteFile(scriptPath, []byte(scriptContent), 0755) //nolint:gosec
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to create mock script: %v", err))
|
||||
}
|
||||
|
||||
@ -15,12 +15,13 @@ import (
|
||||
var _ = Describe("Players", func() {
|
||||
var players Players
|
||||
var repo *mockPlayerRepository
|
||||
ctx := log.NewContext(context.TODO())
|
||||
ctx = request.WithUser(ctx, model.User{ID: "userid", UserName: "johndoe"})
|
||||
ctx = request.WithUsername(ctx, "johndoe")
|
||||
var ctx context.Context
|
||||
var beforeRegister time.Time
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = log.NewContext(GinkgoT().Context())
|
||||
ctx = request.WithUser(ctx, model.User{ID: "userid", UserName: "johndoe"})
|
||||
ctx = request.WithUsername(ctx, "johndoe")
|
||||
repo = &mockPlayerRepository{}
|
||||
ds := &tests.MockDataStore{MockedPlayer: repo, MockedTranscoding: &tests.MockTranscodingRepo{}}
|
||||
players = NewPlayers(ds)
|
||||
@ -124,9 +125,10 @@ var _ = Describe("Players", func() {
|
||||
})
|
||||
|
||||
Context("bad username casing", func() {
|
||||
ctx := log.NewContext(context.TODO())
|
||||
ctx = request.WithUser(ctx, model.User{ID: "userid", UserName: "Johndoe"})
|
||||
ctx = request.WithUsername(ctx, "Johndoe")
|
||||
BeforeEach(func() {
|
||||
ctx = request.WithUser(ctx, model.User{ID: "userid", UserName: "Johndoe"})
|
||||
ctx = request.WithUsername(ctx, "Johndoe")
|
||||
})
|
||||
|
||||
It("finds player by client and user names when not ID is provided", func() {
|
||||
plr := &model.Player{ID: "123", Name: "A Player", Client: "client", UserId: "userid", UserAgent: "chrome", LastSeen: time.Time{}}
|
||||
|
||||
@ -28,9 +28,10 @@ var _ = Describe("Playlists - Import", func() {
|
||||
var ps playlists.Playlists
|
||||
var mockPlsRepo *tests.MockPlaylistRepo
|
||||
var mockLibRepo *tests.MockLibraryRepo
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
mockPlsRepo = tests.CreateMockPlaylistRepo()
|
||||
mockLibRepo = &tests.MockLibraryRepo{}
|
||||
ds = &tests.MockDataStore{
|
||||
|
||||
@ -13,9 +13,10 @@ var _ = Describe("pathResolver", func() {
|
||||
var ds *tests.MockDataStore
|
||||
var mockLibRepo *tests.MockLibraryRepo
|
||||
var resolver *pathResolver
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
tests.SkipOnWindows("path separator bug (#TBD-path-sep-playlists)")
|
||||
mockLibRepo = &tests.MockLibraryRepo{}
|
||||
ds = &tests.MockDataStore{
|
||||
|
||||
@ -15,9 +15,10 @@ import (
|
||||
|
||||
var _ = Describe("parseNSP", func() {
|
||||
var s *playlists
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
s = &playlists{}
|
||||
})
|
||||
|
||||
|
||||
@ -21,9 +21,10 @@ var _ = Describe("Playlists", func() {
|
||||
var ds *tests.MockDataStore
|
||||
var ps playlists.Playlists
|
||||
var mockPlsRepo *tests.MockPlaylistRepo
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
mockPlsRepo = tests.CreateMockPlaylistRepo()
|
||||
ds = &tests.MockDataStore{
|
||||
MockedPlaylist: mockPlsRepo,
|
||||
|
||||
@ -19,9 +19,10 @@ var _ = Describe("REST Adapter", func() {
|
||||
var ds *tests.MockDataStore
|
||||
var ps playlists.Playlists
|
||||
var mockPlsRepo *tests.MockPlaylistRepo
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
mockPlsRepo = tests.CreateMockPlaylistRepo()
|
||||
ds = &tests.MockDataStore{
|
||||
MockedPlaylist: mockPlsRepo,
|
||||
|
||||
@ -28,6 +28,11 @@ func TestPublicURL(t *testing.T) {
|
||||
var _ = configtest.RestoreAfterEachSpec()
|
||||
|
||||
var _ = Describe("Public URL Utilities", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
Describe("PublicURL", func() {
|
||||
When("ShareURL is set", func() {
|
||||
@ -36,13 +41,13 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
})
|
||||
|
||||
It("uses ShareURL as the base", func() {
|
||||
result := publicurl.PublicURL(context.Background(), "/path/to/resource", nil)
|
||||
result := publicurl.PublicURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("https://share.example.com/path/to/resource"))
|
||||
})
|
||||
|
||||
It("includes query parameters", func() {
|
||||
params := url.Values{"size": []string{"300"}, "format": []string{"png"}}
|
||||
result := publicurl.PublicURL(context.Background(), "/image/123", params)
|
||||
result := publicurl.PublicURL(ctx, "/image/123", params)
|
||||
Expect(result).To(ContainSubstring("https://share.example.com/image/123"))
|
||||
Expect(result).To(ContainSubstring("size=300"))
|
||||
Expect(result).To(ContainSubstring("format=png"))
|
||||
@ -55,19 +60,19 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
})
|
||||
|
||||
It("prepends the ShareURL path to the resource", func() {
|
||||
result := publicurl.PublicURL(context.Background(), "/share/img/hash", nil)
|
||||
result := publicurl.PublicURL(ctx, "/share/img/hash", nil)
|
||||
Expect(result).To(Equal("https://example.com/navi/share/img/hash"))
|
||||
})
|
||||
|
||||
It("prepends the ShareURL path and includes query parameters", func() {
|
||||
params := url.Values{"size": []string{"600"}}
|
||||
result := publicurl.PublicURL(context.Background(), "/share/img/hash", params)
|
||||
result := publicurl.PublicURL(ctx, "/share/img/hash", params)
|
||||
Expect(result).To(Equal("https://example.com/navi/share/img/hash?size=600"))
|
||||
})
|
||||
|
||||
It("handles trailing slash in ShareURL path", func() {
|
||||
conf.Update(func(c *conf.Options) { c.ShareURL = "https://example.com/navi/" })
|
||||
result := publicurl.PublicURL(context.Background(), "/share/img/hash", nil)
|
||||
result := publicurl.PublicURL(ctx, "/share/img/hash", nil)
|
||||
Expect(result).To(Equal("https://example.com/navi/share/img/hash"))
|
||||
})
|
||||
})
|
||||
@ -78,14 +83,14 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
})
|
||||
|
||||
It("falls back to AbsoluteURL with request", func() {
|
||||
ctx := request.WithServerAddress(context.Background(), "https", "myserver.com")
|
||||
ctx = request.WithServerAddress(ctx, "https", "myserver.com")
|
||||
result := publicurl.PublicURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("https://myserver.com/path/to/resource"))
|
||||
})
|
||||
|
||||
It("falls back to localhost on the configured port without request", func() {
|
||||
conf.Update(func(c *conf.Options) { c.Port = 4533 })
|
||||
result := publicurl.PublicURL(context.Background(), "/path/to/resource", nil)
|
||||
result := publicurl.PublicURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("http://localhost:4533/path/to/resource"))
|
||||
})
|
||||
})
|
||||
@ -102,13 +107,13 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
})
|
||||
|
||||
It("uses BaseHost and BaseScheme", func() {
|
||||
result := publicurl.AbsoluteURL(context.Background(), "/path/to/resource", nil)
|
||||
result := publicurl.AbsoluteURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("https://configured.example.com/path/to/resource"))
|
||||
})
|
||||
|
||||
It("defaults to http scheme if BaseScheme is empty", func() {
|
||||
conf.Update(func(c *conf.Options) { c.BaseScheme = "" })
|
||||
result := publicurl.AbsoluteURL(context.Background(), "/path/to/resource", nil)
|
||||
result := publicurl.AbsoluteURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("http://configured.example.com/path/to/resource"))
|
||||
})
|
||||
})
|
||||
@ -122,14 +127,14 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
})
|
||||
|
||||
It("extracts host from request", func() {
|
||||
ctx := request.WithServerAddress(context.Background(), "https", "request.example.com")
|
||||
ctx = request.WithServerAddress(ctx, "https", "request.example.com")
|
||||
result := publicurl.AbsoluteURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("https://request.example.com/path/to/resource"))
|
||||
})
|
||||
|
||||
It("falls back to localhost on the configured port without request", func() {
|
||||
conf.Update(func(c *conf.Options) { c.Port = 8080 })
|
||||
result := publicurl.AbsoluteURL(context.Background(), "/path/to/resource", nil)
|
||||
result := publicurl.AbsoluteURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("http://localhost:8080/path/to/resource"))
|
||||
})
|
||||
|
||||
@ -139,7 +144,7 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
c.TLSCert = "cert.pem"
|
||||
c.TLSKey = "key.pem"
|
||||
})
|
||||
result := publicurl.AbsoluteURL(context.Background(), "/path/to/resource", nil)
|
||||
result := publicurl.AbsoluteURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("https://localhost:4533/path/to/resource"))
|
||||
})
|
||||
|
||||
@ -148,7 +153,7 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
c.Port = 4533
|
||||
c.TLSCert = "cert.pem"
|
||||
})
|
||||
result := publicurl.AbsoluteURL(context.Background(), "/path/to/resource", nil)
|
||||
result := publicurl.AbsoluteURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("http://localhost:4533/path/to/resource"))
|
||||
})
|
||||
})
|
||||
@ -163,13 +168,13 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
})
|
||||
|
||||
It("prepends BasePath to the URL", func() {
|
||||
result := publicurl.AbsoluteURL(context.Background(), "/path/to/resource", nil)
|
||||
result := publicurl.AbsoluteURL(ctx, "/path/to/resource", nil)
|
||||
Expect(result).To(Equal("https://example.com/navidrome/path/to/resource"))
|
||||
})
|
||||
})
|
||||
|
||||
It("passes through absolute URLs unchanged", func() {
|
||||
result := publicurl.AbsoluteURL(context.Background(), "https://other.example.com/path", nil)
|
||||
result := publicurl.AbsoluteURL(ctx, "https://other.example.com/path", nil)
|
||||
Expect(result).To(Equal("https://other.example.com/path"))
|
||||
})
|
||||
|
||||
@ -179,7 +184,7 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
c.BaseScheme = "https"
|
||||
})
|
||||
params := url.Values{"key": []string{"value"}}
|
||||
result := publicurl.AbsoluteURL(context.Background(), "/path", params)
|
||||
result := publicurl.AbsoluteURL(ctx, "/path", params)
|
||||
Expect(result).To(Equal("https://example.com/path?key=value"))
|
||||
})
|
||||
})
|
||||
@ -193,19 +198,19 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
|
||||
It("generates a URL with the artwork token", func() {
|
||||
artID := model.NewArtworkID(model.KindAlbumArtwork, "album-123", nil)
|
||||
result := publicurl.ImageURL(context.Background(), artID, 0)
|
||||
result := publicurl.ImageURL(ctx, artID, 0)
|
||||
Expect(result).To(HavePrefix("https://share.example.com/share/img/"))
|
||||
})
|
||||
|
||||
It("includes size parameter when provided", func() {
|
||||
artID := model.NewArtworkID(model.KindArtistArtwork, "artist-1", nil)
|
||||
result := publicurl.ImageURL(context.Background(), artID, 300)
|
||||
result := publicurl.ImageURL(ctx, artID, 300)
|
||||
Expect(result).To(ContainSubstring("size=300"))
|
||||
})
|
||||
|
||||
It("omits size parameter when zero", func() {
|
||||
artID := model.NewArtworkID(model.KindMediaFileArtwork, "track-1", nil)
|
||||
result := publicurl.ImageURL(context.Background(), artID, 0)
|
||||
result := publicurl.ImageURL(ctx, artID, 0)
|
||||
Expect(result).ToNot(ContainSubstring("size="))
|
||||
})
|
||||
})
|
||||
@ -219,7 +224,7 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
})
|
||||
|
||||
It("uses the address of the request that triggered the call", func() {
|
||||
ctx := request.WithServerAddress(context.Background(), "https", "music.example.com")
|
||||
ctx = request.WithServerAddress(ctx, "https", "music.example.com")
|
||||
|
||||
result := publicurl.ImageURL(ctx, artID, 300)
|
||||
Expect(result).To(HavePrefix("https://music.example.com/share/img/"))
|
||||
@ -228,7 +233,7 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
|
||||
It("prefers ShareURL over the address in the context", func() {
|
||||
conf.Update(func(c *conf.Options) { c.ShareURL = "https://share.example.com" })
|
||||
ctx := request.WithServerAddress(context.Background(), "https", "music.example.com")
|
||||
ctx = request.WithServerAddress(ctx, "https", "music.example.com")
|
||||
|
||||
result := publicurl.ImageURL(ctx, artID, 0)
|
||||
Expect(result).To(HavePrefix("https://share.example.com/share/img/"))
|
||||
@ -236,7 +241,7 @@ var _ = Describe("Public URL Utilities", func() {
|
||||
|
||||
It("falls back to localhost on the configured port when no address is available", func() {
|
||||
conf.Update(func(c *conf.Options) { c.Port = 4533 })
|
||||
result := publicurl.ImageURL(context.Background(), artID, 0)
|
||||
result := publicurl.ImageURL(ctx, artID, 0)
|
||||
Expect(result).To(HavePrefix("http://localhost:4533/share/img/"))
|
||||
})
|
||||
})
|
||||
|
||||
@ -23,7 +23,7 @@ var _ = Describe("BufferedScrobbler", func() {
|
||||
var buffer *tests.MockedScrobbleBufferRepo
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
buffer = tests.CreateMockedScrobbleBufferRepo()
|
||||
userRepo := tests.CreateMockUserRepo()
|
||||
Expect(userRepo.Put(ctx, &model.User{ID: "user1", UserName: "alice"})).To(Succeed())
|
||||
@ -142,7 +142,7 @@ func TestBufferedScrobblerBackoffSchedule(t *testing.T) {
|
||||
// Let the loop settle on the empty buffer, then enqueue a scrobble.
|
||||
synctest.Wait()
|
||||
track := model.MediaFile{ID: "123", Title: "Test Track", Artist: "Test Artist"}
|
||||
g.Expect(bs.Scrobble(context.Background(), "user1", Scrobble{MediaFile: track, TimeStamp: time.Now()})).To(Succeed())
|
||||
g.Expect(bs.Scrobble(t.Context(), "user1", Scrobble{MediaFile: track, TimeStamp: time.Now()})).To(Succeed())
|
||||
|
||||
// First attempt fires immediately on the enqueue wake and is left buffered.
|
||||
synctest.Wait()
|
||||
@ -184,7 +184,7 @@ func TestBufferedScrobblerBackoffWindow(t *testing.T) {
|
||||
defer bs.Stop()
|
||||
|
||||
// First enqueue: one immediate attempt, then a 5s window opens.
|
||||
_ = bs.Scrobble(context.Background(), "user1", Scrobble{MediaFile: model.MediaFile{ID: "1"}, TimeStamp: time.Now()})
|
||||
_ = bs.Scrobble(t.Context(), "user1", Scrobble{MediaFile: model.MediaFile{ID: "1"}, TimeStamp: time.Now()})
|
||||
synctest.Wait()
|
||||
if got := scr.ScrobbleAttempts(); got != 1 {
|
||||
t.Fatalf("expected 1 attempt after first enqueue, got %d", got)
|
||||
@ -192,7 +192,7 @@ func TestBufferedScrobblerBackoffWindow(t *testing.T) {
|
||||
|
||||
// A wake inside the window must NOT trigger an early attempt.
|
||||
time.Sleep(1 * time.Second)
|
||||
_ = bs.Scrobble(context.Background(), "user1", Scrobble{MediaFile: model.MediaFile{ID: "2"}, TimeStamp: time.Now()})
|
||||
_ = bs.Scrobble(t.Context(), "user1", Scrobble{MediaFile: model.MediaFile{ID: "2"}, TimeStamp: time.Now()})
|
||||
synctest.Wait()
|
||||
if got := scr.ScrobbleAttempts(); got != 1 {
|
||||
t.Fatalf("wake during backoff drained early: %d attempts", got)
|
||||
@ -218,7 +218,7 @@ func TestBufferedScrobblerHonorsServerDelay(t *testing.T) {
|
||||
bs := newBufferedScrobbler(ds, scr, "test")
|
||||
defer bs.Stop()
|
||||
|
||||
_ = bs.Scrobble(context.Background(), "user1", Scrobble{MediaFile: model.MediaFile{ID: "1"}, TimeStamp: time.Now()})
|
||||
_ = bs.Scrobble(t.Context(), "user1", Scrobble{MediaFile: model.MediaFile{ID: "1"}, TimeStamp: time.Now()})
|
||||
synctest.Wait()
|
||||
if got := scr.ScrobbleAttempts(); got != 1 {
|
||||
t.Fatalf("expected 1 attempt, got %d", got)
|
||||
|
||||
@ -15,9 +15,10 @@ var _ = Describe("Share", func() {
|
||||
var ds model.DataStore
|
||||
var share Share
|
||||
var mockedRepo rest.Persistable[model.Share]
|
||||
ctx := context.Background()
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
ds = &tests.MockDataStore{}
|
||||
mockedRepo = ds.Share().(rest.Persistable[model.Share])
|
||||
share = NewShare(ds)
|
||||
@ -41,7 +42,7 @@ var _ = Describe("Share", func() {
|
||||
})
|
||||
|
||||
It("assigns the logged-in user as owner, ignoring a client-supplied UserID", func() {
|
||||
loggedInCtx := request.WithUser(context.Background(), model.User{ID: "logged-in-user"})
|
||||
loggedInCtx := request.WithUser(ctx, model.User{ID: "logged-in-user"})
|
||||
repo := share.Repository().(rest.Persistable[model.Share])
|
||||
entity := &model.Share{Description: "test", ResourceIDs: "123", UserID: "victim-user"}
|
||||
_, err := repo.Save(loggedInCtx, entity)
|
||||
|
||||
@ -52,7 +52,7 @@ func newLocalStorage(u url.URL) storage.Storage {
|
||||
|
||||
func (s *localStorage) FS() (storage.MusicFS, error) {
|
||||
path := s.u.Path
|
||||
if _, err := os.Stat(path); err != nil { //nolint:gosec
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
return nil, fmt.Errorf("%w: %s", err, path)
|
||||
}
|
||||
return &localFS{FS: os.DirFS(path), extractor: s.extractor, root: path}, nil
|
||||
|
||||
@ -17,10 +17,12 @@ import (
|
||||
)
|
||||
|
||||
var _ = XDescribe("Watcher", func() {
|
||||
var ctx context.Context
|
||||
var lsw storage.Watcher
|
||||
var tmpFolder string
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
tmpFolder = GinkgoT().TempDir()
|
||||
|
||||
local.RegisterExtractor("noop", func(fs fs.FS, path string) local.Extractor { return noopExtractor{} })
|
||||
@ -42,19 +44,16 @@ var _ = XDescribe("Watcher", func() {
|
||||
})
|
||||
|
||||
It("should start and stop watcher", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
watchCtx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
w, err := lsw.Start(ctx)
|
||||
w, err := lsw.Start(watchCtx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
cancel()
|
||||
Eventually(w).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("should return error if watcher is already started", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
_, err := lsw.Start(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = lsw.Start(ctx)
|
||||
@ -62,9 +61,6 @@ var _ = XDescribe("Watcher", func() {
|
||||
})
|
||||
|
||||
It("should detect new files", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
changes, err := lsw.Start(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -75,9 +71,6 @@ var _ = XDescribe("Watcher", func() {
|
||||
})
|
||||
|
||||
It("should detect new subfolders", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
changes, err := lsw.Start(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -87,9 +80,6 @@ var _ = XDescribe("Watcher", func() {
|
||||
})
|
||||
|
||||
It("should detect changes in subfolders recursively", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
subfolder := filepath.Join(tmpFolder, "subfolder1/subfolder2")
|
||||
Expect(os.MkdirAll(subfolder, 0755)).To(Succeed())
|
||||
|
||||
@ -103,8 +93,6 @@ var _ = XDescribe("Watcher", func() {
|
||||
})
|
||||
|
||||
It("should detect removed in files", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
changes, err := lsw.Start(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -118,9 +106,6 @@ var _ = XDescribe("Watcher", func() {
|
||||
})
|
||||
|
||||
It("should detect file moves", func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
filePath := filepath.Join(tmpFolder, "test.txt")
|
||||
Expect(os.WriteFile(filePath, []byte("test"), 0600)).To(Succeed())
|
||||
|
||||
@ -146,7 +131,7 @@ var _ = Describe("Watcher.Start", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
lsw := ls.(storage.Watcher)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
ctx, cancel := context.WithTimeout(GinkgoT().Context(), 3*time.Second)
|
||||
defer cancel()
|
||||
_, err = lsw.Start(ctx)
|
||||
Expect(err).To(HaveOccurred())
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
//nolint:unused
|
||||
package storagetest
|
||||
|
||||
import (
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
//nolint:unused
|
||||
package storagetest_test
|
||||
|
||||
import (
|
||||
|
||||
@ -12,7 +12,11 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("TranscodeLimiter", func() {
|
||||
ctx := log.NewContext(context.TODO())
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = log.NewContext(GinkgoT().Context())
|
||||
})
|
||||
|
||||
Describe("Disabled (both caps <= 0)", func() {
|
||||
It("never blocks and never returns ErrTooManyTranscodes", func() {
|
||||
|
||||
@ -28,9 +28,10 @@ var _ = Describe("MediaStreamer", func() {
|
||||
var streamer stream.MediaStreamer
|
||||
var ds model.DataStore
|
||||
ffmpeg := tests.NewMockFFmpeg("fake data")
|
||||
ctx := log.NewContext(context.TODO())
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = log.NewContext(GinkgoT().Context())
|
||||
cacheDir, _ := os.MkdirTemp("", "file_caches")
|
||||
conf.Update(func(c *conf.Options) {
|
||||
c.CacheFolder = conf.NewDir(cacheDir)
|
||||
@ -41,7 +42,7 @@ var _ = Describe("MediaStreamer", func() {
|
||||
{ID: "123", Path: "tests/fixtures/test.mp3", Suffix: "mp3", BitRate: 128, Duration: 257.0},
|
||||
})
|
||||
testCache := stream.NewTranscodingCache()
|
||||
Eventually(func() bool { return testCache.Available(context.TODO()) }, 10*time.Second).Should(BeTrue())
|
||||
Eventually(func() bool { return testCache.Available(ctx) }, 10*time.Second).Should(BeTrue())
|
||||
streamer = stream.NewMediaStreamer(ds, ffmpeg, testCache)
|
||||
})
|
||||
AfterEach(func() {
|
||||
@ -85,7 +86,7 @@ var _ = Describe("MediaStreamer", func() {
|
||||
c.Transcoding.MaxConcurrentPerUser = 0
|
||||
})
|
||||
tightCache := stream.NewTranscodingCache()
|
||||
Eventually(func() bool { return tightCache.Available(context.TODO()) }, 10*time.Second).Should(BeTrue())
|
||||
Eventually(func() bool { return tightCache.Available(ctx) }, 10*time.Second).Should(BeTrue())
|
||||
tightStreamer := stream.NewMediaStreamer(ds, blockingFFmpeg, tightCache)
|
||||
|
||||
userCtx := request.WithUsername(ctx, "alice")
|
||||
@ -104,7 +105,7 @@ var _ = Describe("MediaStreamer", func() {
|
||||
c.Transcoding.MaxConcurrentPerUser = 0
|
||||
})
|
||||
tightCache := stream.NewTranscodingCache()
|
||||
Eventually(func() bool { return tightCache.Available(context.TODO()) }, 10*time.Second).Should(BeTrue())
|
||||
Eventually(func() bool { return tightCache.Available(ctx) }, 10*time.Second).Should(BeTrue())
|
||||
tightStreamer := stream.NewMediaStreamer(ds, ffmpeg, tightCache)
|
||||
|
||||
userCtx := request.WithUsername(ctx, "alice")
|
||||
@ -126,7 +127,7 @@ var _ = Describe("MediaStreamer", func() {
|
||||
c.Transcoding.MaxConcurrentPerUser = 0
|
||||
})
|
||||
tightCache := stream.NewTranscodingCache()
|
||||
Eventually(func() bool { return tightCache.Available(context.TODO()) }, 10*time.Second).Should(BeTrue())
|
||||
Eventually(func() bool { return tightCache.Available(ctx) }, 10*time.Second).Should(BeTrue())
|
||||
tightStreamer := stream.NewMediaStreamer(ds, ffmpeg, tightCache)
|
||||
|
||||
userCtx := request.WithUsername(ctx, "alice")
|
||||
|
||||
@ -73,7 +73,7 @@ var _ = Describe("database backups", func() {
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
|
||||
ctx = GinkgoT().Context()
|
||||
tempFolder, err := os.MkdirTemp("", "navidrome_backup")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
conf.Update(func(c *conf.Options) { c.Backup.Path = conf.NewDir(tempFolder) })
|
||||
@ -95,8 +95,6 @@ var _ = Describe("database backups", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_ = file.Close()
|
||||
}
|
||||
|
||||
ctx = context.Background()
|
||||
})
|
||||
|
||||
DescribeTable("prune", func(count, expected int) {
|
||||
@ -138,7 +136,7 @@ var _ = Describe("database backups", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeAll(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
DeferCleanup(conf.SnapshotConfig())
|
||||
|
||||
conf.Update(func(c *conf.Options) { c.DbPath = "file::memory:?cache=shared&_foreign_keys=on" })
|
||||
@ -168,7 +166,7 @@ var _ = Describe("database backups", func() {
|
||||
path, err := Backup(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = tests.ClearDB()
|
||||
err = tests.ClearDB(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(IsSchemaEmpty(ctx, Db())).To(BeTrue())
|
||||
|
||||
@ -184,7 +182,7 @@ var _ = Describe("database backups", func() {
|
||||
var dbFilePath string
|
||||
|
||||
BeforeAll(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
DeferCleanup(conf.SnapshotConfig())
|
||||
|
||||
var err error
|
||||
@ -222,7 +220,7 @@ var _ = Describe("database backups", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
singleton.DeleteInstance[*sql.DB]()
|
||||
|
||||
err = tests.ClearDB()
|
||||
err = tests.ClearDB(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By("restoring the backup")
|
||||
|
||||
@ -42,7 +42,7 @@ var _ = Describe("IsSchemaEmpty", func() {
|
||||
var database *sql.DB
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
path := "file::memory:"
|
||||
database, _ = sql.Open(db.Dialect, path)
|
||||
})
|
||||
|
||||
@ -18,7 +18,7 @@ const idColumnsMigrationVersion = 20260720015443
|
||||
|
||||
var _ = Describe("idColumns inventory", func() {
|
||||
It("covers every id-bearing column present at the migration version", func() {
|
||||
ctx := context.Background()
|
||||
ctx := GinkgoT().Context()
|
||||
db, err := sql.Open("sqlite3", "file::memory:")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
db.SetMaxOpenConns(1) // non-shared :memory: — a second conn would be an empty DB
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
|
||||
@ -15,7 +14,6 @@ import (
|
||||
var _ = Describe("upUniformCanonicalIds", func() {
|
||||
var db *sql.DB
|
||||
var tx *sql.Tx
|
||||
ctx := context.Background()
|
||||
|
||||
const (
|
||||
hashID = "5cLJPkLA5DK2BADhoeotPk" // canonical, kept
|
||||
@ -98,7 +96,7 @@ var _ = Describe("upUniformCanonicalIds", func() {
|
||||
var err error
|
||||
tx, err = db.Begin()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(upUniformCanonicalIds(ctx, tx)).To(Succeed())
|
||||
Expect(upUniformCanonicalIds(GinkgoT().Context(), tx)).To(Succeed())
|
||||
Expect(tx.Commit()).To(Succeed())
|
||||
})
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ var _ = Describe("Optimize", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
now = time.Date(2026, time.July, 9, 12, 0, 0, 0, time.UTC)
|
||||
var err error
|
||||
database, err = sql.Open(db.Dialect, "file::memory:")
|
||||
|
||||
@ -105,7 +105,7 @@ func VerifyFTS(ctx context.Context, database *sql.DB) error {
|
||||
|
||||
func verifyFTS(ctx context.Context, database execer) error {
|
||||
for _, table := range ftsTables {
|
||||
stmt := fmt.Sprintf("INSERT INTO %[1]s(%[1]s) VALUES('integrity-check')", table) //nolint:gosec // fixed table list
|
||||
stmt := fmt.Sprintf("INSERT INTO %[1]s(%[1]s) VALUES('integrity-check')", table)
|
||||
if _, err := database.ExecContext(ctx, stmt); err != nil {
|
||||
return fmt.Errorf("verifying %s: %w", table, err)
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ var _ = Describe("RebuildFTS schema guard", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
It("refuses to run on a schema older than the FTS migration", func() {
|
||||
@ -129,7 +129,7 @@ var _ = Describe("Repair", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
database = newDB(ctx, 0)
|
||||
|
||||
for _, stmt := range []string{
|
||||
|
||||
@ -25,8 +25,10 @@ func TestLog(t *testing.T) {
|
||||
var _ = Describe("Logger", func() {
|
||||
var l *logrus.Logger
|
||||
var hook *test.Hook
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
l, hook = test.NewNullLogger()
|
||||
SetLevel(LevelTrace)
|
||||
SetDefaultLogger(l)
|
||||
@ -46,7 +48,7 @@ var _ = Describe("Logger", func() {
|
||||
})
|
||||
|
||||
It("Empty context", func() {
|
||||
Error(context.TODO(), "Simple Message")
|
||||
Error(ctx, "Simple Message")
|
||||
Expect(hook.LastEntry().Message).To(Equal("Simple Message"))
|
||||
Expect(hook.LastEntry().Data).To(BeEmpty())
|
||||
})
|
||||
@ -74,7 +76,7 @@ var _ = Describe("Logger", func() {
|
||||
})
|
||||
|
||||
It("can get data from the request's context", func() {
|
||||
ctx := NewContext(context.TODO(), "foo", "bar")
|
||||
ctx = NewContext(ctx, "foo", "bar")
|
||||
req := httptest.NewRequest("get", "/", nil).WithContext(ctx)
|
||||
|
||||
Error(req, "Simple Message", "key1", "value1")
|
||||
@ -95,7 +97,7 @@ var _ = Describe("Logger", func() {
|
||||
SetLogSourceLine(true)
|
||||
Error("A crash happened")
|
||||
// NOTE: This assertion breaks if the line number above changes
|
||||
Expect(hook.LastEntry().Data[" source"]).To(ContainSubstring("/log/log_test.go:96"))
|
||||
Expect(hook.LastEntry().Data[" source"]).To(ContainSubstring("/log/log_test.go:98"))
|
||||
Expect(hook.LastEntry().Message).To(Equal("A crash happened"))
|
||||
})
|
||||
|
||||
@ -214,7 +216,6 @@ var _ = Describe("Logger", func() {
|
||||
|
||||
It("returns the logger from context if it has one", func() {
|
||||
logger := logrus.NewEntry(logrus.New())
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, loggerCtxKey, logger)
|
||||
|
||||
Expect(extractLogger(ctx)).To(Equal(logger))
|
||||
@ -222,7 +223,6 @@ var _ = Describe("Logger", func() {
|
||||
|
||||
It("returns the logger from request's context if it has one", func() {
|
||||
logger := logrus.NewEntry(logrus.New())
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, loggerCtxKey, logger)
|
||||
req := httptest.NewRequest("get", "/", nil).WithContext(ctx)
|
||||
|
||||
@ -334,14 +334,14 @@ var _ = Describe("Logger", func() {
|
||||
}
|
||||
cfg := configOptions{
|
||||
Address: "0.0.0.0",
|
||||
LastFM: lastfmOptions{ //nolint:gosec
|
||||
LastFM: lastfmOptions{
|
||||
Enabled: true,
|
||||
ApiKey: "0123456789abcdef0123456789abcdef",
|
||||
Secret: "fedcba9876543210fedcba9876543210",
|
||||
Language: "en",
|
||||
Languages: []string{"en"},
|
||||
},
|
||||
Prometheus: prometheusOptions{ //nolint:gosec
|
||||
Prometheus: prometheusOptions{
|
||||
Enabled: true,
|
||||
MetricsPath: "/metrics",
|
||||
Password: `prom"pass-tail`,
|
||||
|
||||
@ -54,7 +54,6 @@ type levelThresholdTest struct {
|
||||
// above and including the level given. If the provided level does not exit,
|
||||
// an empty slice is returned.
|
||||
func levelThreshold(l logrus.Level) []logrus.Level {
|
||||
//nolint
|
||||
if l < 0 || int(l) > len(logrus.AllLevels) {
|
||||
return []logrus.Level{}
|
||||
}
|
||||
@ -100,7 +99,7 @@ type EntryDataValuesTest struct {
|
||||
redactionList []string
|
||||
logFields logrus.Fields
|
||||
expected logrus.Fields
|
||||
description string //nolint
|
||||
description string
|
||||
}
|
||||
|
||||
// Test that any occurrence of a redaction pattern
|
||||
|
||||
@ -8,14 +8,19 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("Token epoch holder", func() {
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
It("reports nothing when unset", func() {
|
||||
ctx := WithTokenEpochHolder(context.TODO())
|
||||
ctx = WithTokenEpochHolder(ctx)
|
||||
_, ok := TokenEpochFrom(ctx)
|
||||
Expect(ok).To(BeFalse())
|
||||
})
|
||||
|
||||
It("round-trips a value set by the handler", func() {
|
||||
ctx := WithTokenEpochHolder(context.TODO())
|
||||
ctx = WithTokenEpochHolder(ctx)
|
||||
SetTokenEpoch(ctx, 7)
|
||||
|
||||
epoch, ok := TokenEpochFrom(ctx)
|
||||
@ -24,7 +29,7 @@ var _ = Describe("Token epoch holder", func() {
|
||||
})
|
||||
|
||||
It("survives being wrapped in a derived context", func() {
|
||||
ctx := WithTokenEpochHolder(context.TODO())
|
||||
ctx = WithTokenEpochHolder(ctx)
|
||||
SetTokenEpoch(context.WithValue(ctx, contextKey("unrelated"), 1), 3)
|
||||
|
||||
epoch, ok := TokenEpochFrom(ctx)
|
||||
@ -33,20 +38,25 @@ var _ = Describe("Token epoch holder", func() {
|
||||
})
|
||||
|
||||
It("is a no-op with no holder installed", func() {
|
||||
Expect(func() { SetTokenEpoch(context.TODO(), 5) }).ToNot(Panic())
|
||||
_, ok := TokenEpochFrom(context.TODO())
|
||||
Expect(func() { SetTokenEpoch(ctx, 5) }).ToNot(Panic())
|
||||
_, ok := TokenEpochFrom(ctx)
|
||||
Expect(ok).To(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("Server address", func() {
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
It("reports nothing when unset", func() {
|
||||
_, _, ok := ServerAddressFrom(context.TODO())
|
||||
_, _, ok := ServerAddressFrom(ctx)
|
||||
Expect(ok).To(BeFalse())
|
||||
})
|
||||
|
||||
It("round-trips the scheme and host", func() {
|
||||
ctx := WithServerAddress(context.TODO(), "https", "music.example.com")
|
||||
ctx = WithServerAddress(ctx, "https", "music.example.com")
|
||||
|
||||
scheme, host, ok := ServerAddressFrom(ctx)
|
||||
Expect(ok).To(BeTrue())
|
||||
@ -55,16 +65,16 @@ var _ = Describe("Server address", func() {
|
||||
})
|
||||
|
||||
It("reports nothing when the host is empty", func() {
|
||||
ctx := WithServerAddress(context.TODO(), "https", "")
|
||||
ctx = WithServerAddress(ctx, "https", "")
|
||||
|
||||
_, _, ok := ServerAddressFrom(ctx)
|
||||
Expect(ok).To(BeFalse())
|
||||
})
|
||||
|
||||
It("is carried over to a background context by AddValues", func() {
|
||||
reqCtx := WithServerAddress(context.TODO(), "https", "music.example.com")
|
||||
reqCtx := WithServerAddress(ctx, "https", "music.example.com")
|
||||
|
||||
_, host, ok := ServerAddressFrom(AddValues(context.Background(), reqCtx))
|
||||
_, host, ok := ServerAddressFrom(AddValues(ctx, reqCtx))
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(host).To(Equal("music.example.com"))
|
||||
})
|
||||
|
||||
@ -29,7 +29,7 @@ type User struct {
|
||||
TokenEpoch int `structs:"-" json:"-"`
|
||||
// This is used to set or change a password when calling Put. If it is empty, the password is not changed.
|
||||
// It is received from the UI with the name "password"
|
||||
NewPassword string `structs:"password,omitempty" json:"password,omitempty"` //nolint:gosec
|
||||
NewPassword string `structs:"password,omitempty" json:"password,omitempty"`
|
||||
// If changing the password, this is also required
|
||||
CurrentPassword string `structs:"current_password,omitempty" json:"currentPassword,omitempty"`
|
||||
}
|
||||
|
||||
@ -50,9 +50,9 @@ var _ = Describe("Artwork hydration", func() {
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = request.WithUser(log.NewContext(GinkgoT().Context()), adminUser)
|
||||
clearArtworkTables()
|
||||
DeferCleanup(clearArtworkTables)
|
||||
ctx = request.WithUser(log.NewContext(context.Background()), adminUser)
|
||||
aw = NewArtworkRepository(GetDBXBuilder())
|
||||
})
|
||||
|
||||
@ -571,7 +571,7 @@ var _ = Describe("Artwork hydration", func() {
|
||||
})
|
||||
|
||||
It("keeps a non-admin from streaming another user's private playlists", func() {
|
||||
otherCtx := request.WithUser(log.NewContext(context.Background()), regularUser)
|
||||
otherCtx := request.WithUser(ctx, regularUser)
|
||||
repo := NewPlaylistRepository(GetDBXBuilder())
|
||||
opts := model.QueryOptions{Sort: "name", Filters: onlyPlaylists}
|
||||
|
||||
|
||||
@ -32,12 +32,12 @@ func BenchmarkSmartPlaylistRole(b *testing.B) {
|
||||
b.Cleanup(conf.SnapshotConfig())
|
||||
tmpDir := b.TempDir()
|
||||
conf.Update(func(c *conf.Options) { c.DbPath = filepath.Join(tmpDir, "bench-smartpl.db") })
|
||||
cleanup := db.Init(context.Background())
|
||||
cleanup := db.Init(b.Context())
|
||||
defer cleanup()
|
||||
log.SetLevel(log.LevelFatal)
|
||||
|
||||
conn := dbx.NewFromDB(db.Db(), db.Dialect)
|
||||
ctx := log.NewContext(context.Background())
|
||||
ctx := log.NewContext(b.Context())
|
||||
user := model.User{ID: "bench-user", UserName: "bench", Name: "Bench User", IsAdmin: true}
|
||||
ctx = request.WithUser(ctx, user)
|
||||
|
||||
@ -67,12 +67,12 @@ func BenchmarkSmartPlaylistNegatedRole(b *testing.B) {
|
||||
b.Cleanup(conf.SnapshotConfig())
|
||||
tmpDir := b.TempDir()
|
||||
conf.Update(func(c *conf.Options) { c.DbPath = filepath.Join(tmpDir, "bench-smartpl-neg.db") })
|
||||
cleanup := db.Init(context.Background())
|
||||
cleanup := db.Init(b.Context())
|
||||
defer cleanup()
|
||||
log.SetLevel(log.LevelFatal)
|
||||
|
||||
conn := dbx.NewFromDB(db.Db(), db.Dialect)
|
||||
ctx := log.NewContext(context.Background())
|
||||
ctx := log.NewContext(b.Context())
|
||||
user := model.User{ID: "bench-user", UserName: "bench", Name: "Bench User", IsAdmin: true}
|
||||
ctx = request.WithUser(ctx, user)
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ var _ = Describe("FolderRepository", func() {
|
||||
var testLib, otherLib model.Library
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = request.WithUser(log.NewContext(context.TODO()), model.User{ID: "userid"})
|
||||
ctx = request.WithUser(log.NewContext(GinkgoT().Context()), model.User{ID: "userid"})
|
||||
conn = GetDBXBuilder()
|
||||
repo = newFolderRepository(conn)
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ var _ = Describe("LibraryRepository", func() {
|
||||
var conn *dbx.DB
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = request.WithUser(log.NewContext(context.TODO()), model.User{ID: "userid"})
|
||||
ctx = request.WithUser(log.NewContext(GinkgoT().Context()), model.User{ID: "userid"})
|
||||
conn = GetDBXBuilder()
|
||||
repo = NewLibraryRepository(conn)
|
||||
})
|
||||
@ -176,7 +176,7 @@ var _ = Describe("LibraryRepository", func() {
|
||||
DeferCleanup(lockConn.Close)
|
||||
_, err = lockConn.ExecContext(ctx, "BEGIN IMMEDIATE")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
DeferCleanup(func() { _, _ = lockConn.ExecContext(context.Background(), "ROLLBACK") })
|
||||
DeferCleanup(func() { _, _ = lockConn.ExecContext(context.WithoutCancel(ctx), "ROLLBACK") })
|
||||
|
||||
Expect(repo.StoreMusicFolder(ctx)).To(Succeed())
|
||||
})
|
||||
|
||||
@ -35,7 +35,6 @@ var _ = Describe("MediaRepository", func() {
|
||||
var albumRoot, disc1, sibling *model.Folder
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx := request.WithUser(log.NewContext(context.TODO()), model.User{ID: "userid"})
|
||||
libPtr, err := NewLibraryRepository(GetDBXBuilder()).Get(ctx, 1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
lib = *libPtr
|
||||
@ -384,7 +383,7 @@ var _ = Describe("MediaRepository", func() {
|
||||
Expect(mr.Put(ctx, &new2)).To(Succeed())
|
||||
Expect(mr.MarkMissing(ctx, true, &new1, &new2)).To(Succeed())
|
||||
|
||||
adminCtx := request.WithUser(log.NewContext(context.TODO()), model.User{ID: "userid", IsAdmin: true})
|
||||
adminCtx := request.WithUser(ctx, model.User{ID: "userid", IsAdmin: true})
|
||||
adminRepo := NewMediaFileRepository(GetDBXBuilder())
|
||||
|
||||
// Ensure the files are marked as missing and we have 2 of them
|
||||
@ -920,7 +919,6 @@ var _ = Describe("MediaRepository", func() {
|
||||
var pls model.Playlist
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx := request.WithUser(log.NewContext(context.TODO()), model.User{ID: "userid"})
|
||||
pr = NewPlaylistRepository(GetDBXBuilder())
|
||||
prev = model.MediaFile{ID: "reassign-prev", LibraryID: 1, Path: "reassign/prev.mp3", Title: "Prev"}
|
||||
next = model.MediaFile{ID: "reassign-next", LibraryID: 1, Path: "reassign/next.mp3", Title: "Next"}
|
||||
@ -962,7 +960,6 @@ var _ = Describe("MediaRepository", func() {
|
||||
})
|
||||
|
||||
It("moves scrobbles and buffered scrobbles onto the new id", func() {
|
||||
ctx := request.WithUser(log.NewContext(context.TODO()), model.User{ID: "userid"})
|
||||
scrobbles := NewScrobbleRepository(GetDBXBuilder())
|
||||
buffer := NewScrobbleBufferRepository(GetDBXBuilder())
|
||||
Expect(scrobbles.RecordScrobble(ctx, prev.ID, time.Now())).To(Succeed())
|
||||
|
||||
@ -26,7 +26,7 @@ func TestPersistence(t *testing.T) {
|
||||
//os.Remove("./test-123.db")
|
||||
//conf.Server.DbPath = "./test-123.db"
|
||||
conf.Update(func(c *conf.Options) { c.DbPath = "file::memory:?cache=shared&_foreign_keys=on" })
|
||||
defer db.Init(context.Background())()
|
||||
defer db.Init(t.Context())()
|
||||
log.SetLevel(log.LevelFatal)
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Persistence Suite")
|
||||
@ -196,7 +196,7 @@ func restrictedFixture(name string) (context.Context, model.Library, model.User)
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
conn := GetDBXBuilder()
|
||||
ctx := log.NewContext(context.TODO())
|
||||
ctx := log.NewContext(GinkgoT().Context())
|
||||
ctx = request.WithUser(ctx, adminUser)
|
||||
|
||||
ur := NewUserRepository(conn)
|
||||
|
||||
@ -16,8 +16,8 @@ var _ = Describe("SQLStore", func() {
|
||||
var ds model.DataStore
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
ds = New(db.Db())
|
||||
ctx = context.Background()
|
||||
})
|
||||
Describe("WithTx", func() {
|
||||
Context("When block returns nil", func() {
|
||||
|
||||
@ -18,7 +18,7 @@ var _ = Describe("PlayQueueRepository", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = log.NewContext(context.TODO())
|
||||
ctx = log.NewContext(GinkgoT().Context())
|
||||
ctx = request.WithUser(ctx, model.User{ID: "userid", UserName: "userid", IsAdmin: true})
|
||||
repo = NewPlayQueueRepository(GetDBXBuilder())
|
||||
})
|
||||
|
||||
@ -208,12 +208,12 @@ var _ = Describe("PluginRepository", func() {
|
||||
|
||||
It("does not need the write lock when no plugins have errors", func() {
|
||||
_ = repo.Put(ctx, &model.Plugin{ID: "clean-plugin", Path: "/plugins/c.wasm", Manifest: "{}", SHA256: "h1"})
|
||||
conn, err := db.Db().Conn(GinkgoT().Context())
|
||||
conn, err := db.Db().Conn(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
DeferCleanup(conn.Close)
|
||||
_, err = conn.ExecContext(GinkgoT().Context(), "BEGIN IMMEDIATE")
|
||||
_, err = conn.ExecContext(ctx, "BEGIN IMMEDIATE")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
DeferCleanup(func() { _, _ = conn.ExecContext(context.Background(), "ROLLBACK") })
|
||||
DeferCleanup(func() { _, _ = conn.ExecContext(context.WithoutCancel(ctx), "ROLLBACK") })
|
||||
|
||||
Expect(repo.ClearErrors(ctx)).To(Succeed())
|
||||
})
|
||||
|
||||
@ -18,6 +18,10 @@ var _ = Describe("ScrobbleRepository", func() {
|
||||
var repo model.ScrobbleRepository
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
Describe("RecordScrobble", func() {
|
||||
var fileID string
|
||||
var userID string
|
||||
@ -26,7 +30,7 @@ var _ = Describe("ScrobbleRepository", func() {
|
||||
BeforeEach(func() {
|
||||
fileID = id.NewRandom()
|
||||
userID = id.NewRandom()
|
||||
ctx = request.WithUser(log.NewContext(GinkgoT().Context()), model.User{ID: userID, UserName: "johndoe", IsAdmin: true})
|
||||
ctx = request.WithUser(log.NewContext(ctx), model.User{ID: userID, UserName: "johndoe", IsAdmin: true})
|
||||
db := GetDBXBuilder()
|
||||
repo = NewScrobbleRepository(db)
|
||||
|
||||
@ -85,7 +89,7 @@ var _ = Describe("ScrobbleRepository", func() {
|
||||
|
||||
Context("admin user (id userid)", func() {
|
||||
BeforeEach(func() {
|
||||
ctx = request.WithUser(log.NewContext(context.TODO()), adminUser)
|
||||
ctx = request.WithUser(log.NewContext(ctx), adminUser)
|
||||
repo = NewScrobbleRepository(GetDBXBuilder())
|
||||
})
|
||||
|
||||
@ -154,7 +158,7 @@ var _ = Describe("ScrobbleRepository", func() {
|
||||
|
||||
Context("non-admin user", func() {
|
||||
BeforeEach(func() {
|
||||
ctx = request.WithUser(log.NewContext(context.TODO()), regularUser)
|
||||
ctx = request.WithUser(log.NewContext(ctx), regularUser)
|
||||
repo = NewScrobbleRepository(GetDBXBuilder())
|
||||
})
|
||||
|
||||
|
||||
@ -455,7 +455,7 @@ var _ = Describe("ShareRepository", func() {
|
||||
})
|
||||
|
||||
It("returns not found when updating a nonexistent share", func() {
|
||||
ctx := request.WithUser(log.NewContext(context.TODO()), ownerUser)
|
||||
ctx := request.WithUser(ctx, ownerUser)
|
||||
repo := NewShareRepository(GetDBXBuilder())
|
||||
err := repo.Update(ctx, "does-not-exist", model.Share{Description: "Ghost"}, "description")
|
||||
Expect(err).To(Equal(rest.ErrNotFound))
|
||||
@ -463,7 +463,7 @@ var _ = Describe("ShareRepository", func() {
|
||||
|
||||
It("updates all columns when no specific columns are given", func() {
|
||||
insertShare("all-cols-share", ownerUser.ID)
|
||||
ctx := request.WithUser(log.NewContext(context.TODO()), ownerUser)
|
||||
ctx := request.WithUser(ctx, ownerUser)
|
||||
repo := NewShareRepository(GetDBXBuilder())
|
||||
// No cols: the update must write every column, not just updated_at.
|
||||
err := repo.Update(ctx, "all-cols-share",
|
||||
@ -479,7 +479,7 @@ var _ = Describe("ShareRepository", func() {
|
||||
|
||||
It("does not let an owner reassign their share to another user", func() {
|
||||
insertShare("reassign-share", ownerUser.ID)
|
||||
ctx := request.WithUser(log.NewContext(context.TODO()), ownerUser)
|
||||
ctx := request.WithUser(ctx, ownerUser)
|
||||
repo := NewShareRepository(GetDBXBuilder())
|
||||
err := repo.Update(ctx, "reassign-share",
|
||||
model.Share{UserID: otherUser.ID, Description: "Given away"}, "user_id", "description")
|
||||
|
||||
@ -12,6 +12,12 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("sqlRestful", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
Describe("parseRestFilters", func() {
|
||||
var r sqlRepository
|
||||
var options rest.QueryOptions
|
||||
@ -22,7 +28,7 @@ var _ = Describe("sqlRestful", func() {
|
||||
|
||||
It("returns nil if filters is empty", func() {
|
||||
options.Filters = nil
|
||||
Expect(r.parseRestFilters(context.Background(), options)).To(BeNil())
|
||||
Expect(r.parseRestFilters(ctx, options)).To(BeNil())
|
||||
})
|
||||
|
||||
It(`returns nil if tries a filter with legacySearchExpr("'")`, func() {
|
||||
@ -31,7 +37,7 @@ var _ = Describe("sqlRestful", func() {
|
||||
"name": fullTextFilter("table"),
|
||||
}
|
||||
options.Filters = map[string]any{"name": "'"}
|
||||
Expect(r.parseRestFilters(context.Background(), options)).To(BeEmpty())
|
||||
Expect(r.parseRestFilters(ctx, options)).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("does not add nill filters", func() {
|
||||
@ -41,22 +47,22 @@ var _ = Describe("sqlRestful", func() {
|
||||
},
|
||||
}
|
||||
options.Filters = map[string]any{"name": "joe"}
|
||||
Expect(r.parseRestFilters(context.Background(), options)).To(BeEmpty())
|
||||
Expect(r.parseRestFilters(ctx, options)).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("returns a '=' condition for 'id' filter", func() {
|
||||
options.Filters = map[string]any{"id": "123"}
|
||||
Expect(r.parseRestFilters(context.Background(), options)).To(Equal(squirrel.And{squirrel.Eq{"id": "123"}}))
|
||||
Expect(r.parseRestFilters(ctx, options)).To(Equal(squirrel.And{squirrel.Eq{"id": "123"}}))
|
||||
})
|
||||
|
||||
It("returns a 'in' condition for multiples 'id' filters", func() {
|
||||
options.Filters = map[string]any{"id": []string{"123", "456"}}
|
||||
Expect(r.parseRestFilters(context.Background(), options)).To(Equal(squirrel.And{squirrel.Eq{"id": []string{"123", "456"}}}))
|
||||
Expect(r.parseRestFilters(ctx, options)).To(Equal(squirrel.And{squirrel.Eq{"id": []string{"123", "456"}}}))
|
||||
})
|
||||
|
||||
It("returns a 'like' condition for other filters", func() {
|
||||
options.Filters = map[string]any{"name": "joe"}
|
||||
Expect(r.parseRestFilters(context.Background(), options)).To(Equal(squirrel.And{squirrel.Like{"name": "joe%"}}))
|
||||
Expect(r.parseRestFilters(ctx, options)).To(Equal(squirrel.And{squirrel.Like{"name": "joe%"}}))
|
||||
})
|
||||
|
||||
It("uses the custom filter", func() {
|
||||
@ -66,7 +72,7 @@ var _ = Describe("sqlRestful", func() {
|
||||
},
|
||||
}
|
||||
options.Filters = map[string]any{"test": 100}
|
||||
Expect(r.parseRestFilters(context.Background(), options)).To(Equal(squirrel.And{squirrel.Gt{"test": 100}}))
|
||||
Expect(r.parseRestFilters(ctx, options)).To(Equal(squirrel.And{squirrel.Gt{"test": 100}}))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ const (
|
||||
|
||||
var _ = Describe("Tag Library Filtering", func() {
|
||||
var (
|
||||
ctx context.Context
|
||||
tagRockID = id.NewTagID(tagNameGenre, tagValueRock)
|
||||
tagPopID = id.NewTagID(tagNameGenre, tagValuePop)
|
||||
tagJazzID = id.NewTagID(tagNameGenre, tagValueJazz)
|
||||
@ -43,6 +44,7 @@ var _ = Describe("Tag Library Filtering", func() {
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
|
||||
// Generate unique path suffix to avoid conflicts with other tests
|
||||
uniqueSuffix := time.Now().Format("20060102150405.000")
|
||||
@ -75,7 +77,7 @@ var _ = Describe("Tag Library Filtering", func() {
|
||||
}
|
||||
|
||||
// Create test tags
|
||||
adminCtx := request.WithUser(log.NewContext(context.TODO()), adminUser)
|
||||
adminCtx := request.WithUser(log.NewContext(ctx), adminUser)
|
||||
tagRepo := NewTagRepository(GetDBXBuilder())
|
||||
|
||||
createTag := func(libraryID int, name, value string) {
|
||||
@ -110,11 +112,9 @@ var _ = Describe("Tag Library Filtering", func() {
|
||||
Describe("TagRepository Library Filtering", func() {
|
||||
// Helper to create repository and read all tags
|
||||
readAllTags := func(user *model.User, filters ...rest.QueryOptions) model.TagList {
|
||||
var ctx context.Context
|
||||
userCtx := ctx
|
||||
if user != nil {
|
||||
ctx = request.WithUser(log.NewContext(context.TODO()), *user)
|
||||
} else {
|
||||
ctx = context.Background() // Headless context
|
||||
userCtx = request.WithUser(log.NewContext(ctx), *user)
|
||||
}
|
||||
|
||||
repo := NewTagRepository(GetDBXBuilder())
|
||||
@ -124,23 +124,21 @@ var _ = Describe("Tag Library Filtering", func() {
|
||||
opts = filters[0]
|
||||
}
|
||||
|
||||
tags, err := repo.ReadAll(ctx, opts)
|
||||
tags, err := repo.ReadAll(userCtx, opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
return tags
|
||||
}
|
||||
|
||||
// Helper to count tags
|
||||
countTags := func(user *model.User) int64 {
|
||||
var ctx context.Context
|
||||
userCtx := ctx
|
||||
if user != nil {
|
||||
ctx = request.WithUser(log.NewContext(context.TODO()), *user)
|
||||
} else {
|
||||
ctx = context.Background()
|
||||
userCtx = request.WithUser(log.NewContext(ctx), *user)
|
||||
}
|
||||
|
||||
repo := NewTagRepository(GetDBXBuilder())
|
||||
|
||||
count, err := repo.Count(ctx)
|
||||
count, err := repo.Count(userCtx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
return count
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ var _ = Describe("TagRepository", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = request.WithUser(log.NewContext(context.TODO()), model.User{ID: "userid", UserName: "johndoe", IsAdmin: true})
|
||||
ctx = request.WithUser(log.NewContext(GinkgoT().Context()), model.User{ID: "userid", UserName: "johndoe", IsAdmin: true})
|
||||
tagRepo := NewTagRepository(GetDBXBuilder())
|
||||
repo = tagRepo
|
||||
restRepo = tagRepo
|
||||
|
||||
@ -749,8 +749,7 @@ var _ = Describe("UserRepository", func() {
|
||||
var wg sync.WaitGroup
|
||||
for range callers {
|
||||
wg.Go(func() {
|
||||
ctx := log.NewContext(context.TODO())
|
||||
ctx = request.WithUser(ctx, model.User{ID: usr.ID})
|
||||
ctx := request.WithUser(ctx, model.User{ID: usr.ID})
|
||||
ctx = request.WithTokenEpochHolder(ctx)
|
||||
own := NewUserRepository(GetDBXBuilder())
|
||||
|
||||
@ -777,8 +776,7 @@ var _ = Describe("UserRepository", func() {
|
||||
|
||||
Describe("Put and the token epoch", func() {
|
||||
newRepo := func(actingUserID string) (context.Context, model.UserRepository) {
|
||||
ctx := log.NewContext(context.TODO())
|
||||
ctx = request.WithUser(ctx, model.User{ID: actingUserID, IsAdmin: true})
|
||||
ctx := request.WithUser(ctx, model.User{ID: actingUserID, IsAdmin: true})
|
||||
ctx = request.WithTokenEpochHolder(ctx)
|
||||
return ctx, NewUserRepository(GetDBXBuilder())
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ var _ = Describe("CacheService", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
service = newCacheService("test_plugin")
|
||||
})
|
||||
|
||||
|
||||
@ -122,7 +122,7 @@ var _ = Describe("ConfigService", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
Describe("newConfigService", func() {
|
||||
|
||||
@ -125,7 +125,7 @@ func (s *httpServiceImpl) Send(ctx context.Context, request host.HTTPRequest) (*
|
||||
}
|
||||
|
||||
// Execute request
|
||||
resp, err := s.client.Do(httpReq) //nolint:gosec // URL is validated against requiredHosts
|
||||
resp, err := s.client.Do(httpReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -16,11 +16,13 @@ import (
|
||||
|
||||
var _ = Describe("httpServiceImpl", func() {
|
||||
var (
|
||||
ctx context.Context
|
||||
svc *httpServiceImpl
|
||||
ts *httptest.Server
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
stubLocalhostDNS()
|
||||
})
|
||||
|
||||
@ -39,7 +41,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
@ -54,7 +56,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
}))
|
||||
// The trailing dot passes the pre-flight string check; only the dial-time guard catches it.
|
||||
_, port, _ := net.SplitHostPort(strings.TrimPrefix(ts.URL, "http://"))
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://localhost.:" + port + "/test",
|
||||
TimeoutMs: 1000,
|
||||
@ -64,7 +66,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
})
|
||||
|
||||
It("should block requests to localhost by name", func() {
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://localhost:12345/test",
|
||||
TimeoutMs: 1000,
|
||||
@ -74,7 +76,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
})
|
||||
|
||||
It("should block requests to private IPs (10.x)", func() {
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://10.0.0.1/test",
|
||||
TimeoutMs: 1000,
|
||||
@ -84,7 +86,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
})
|
||||
|
||||
It("should block requests to private IPs (192.168.x)", func() {
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://192.168.1.1/test",
|
||||
TimeoutMs: 1000,
|
||||
@ -94,7 +96,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
})
|
||||
|
||||
It("should block requests to private IPs (172.16.x)", func() {
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://172.16.0.1/test",
|
||||
TimeoutMs: 1000,
|
||||
@ -104,7 +106,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
})
|
||||
|
||||
It("should block requests to link-local IPs (169.254.x)", func() {
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://169.254.169.254/latest/meta-data/",
|
||||
TimeoutMs: 1000,
|
||||
@ -114,7 +116,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
})
|
||||
|
||||
It("should block requests to IPv6 loopback with port", func() {
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://[::1]:8080/test",
|
||||
TimeoutMs: 1000,
|
||||
@ -124,7 +126,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
})
|
||||
|
||||
It("should block requests to IPv6 loopback without port", func() {
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://[::1]/test",
|
||||
TimeoutMs: 1000,
|
||||
@ -136,7 +138,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
It("should allow requests to public hostnames", func() {
|
||||
// This will fail at the network level (connection refused or DNS),
|
||||
// but it should NOT fail with a "private/loopback" error
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://203.0.113.1:1/test", // TEST-NET-3, non-routable but not private
|
||||
TimeoutMs: 100,
|
||||
@ -148,7 +150,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
})
|
||||
|
||||
It("should return error for invalid URL", func() {
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "://bad-url",
|
||||
})
|
||||
@ -156,7 +158,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
})
|
||||
|
||||
It("should reject non-http/https URL schemes", func() {
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "ftp://example.com/file",
|
||||
})
|
||||
@ -179,7 +181,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
w.WriteHeader(201)
|
||||
_, _ = w.Write([]byte("hello"))
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
Headers: map[string]string{"Accept": "text/plain"},
|
||||
@ -197,7 +199,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
_, _ = w.Write([]byte("got:" + string(b)))
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "POST",
|
||||
URL: ts.URL,
|
||||
Body: []byte("abc"),
|
||||
@ -213,7 +215,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
_, _ = w.Write([]byte("put:" + string(b)))
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "PUT",
|
||||
URL: ts.URL,
|
||||
Body: []byte("xyz"),
|
||||
@ -228,7 +230,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
Expect(r.Method).To(Equal("DELETE"))
|
||||
w.WriteHeader(204)
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "DELETE",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
@ -243,7 +245,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
_, _ = w.Write([]byte("del:" + string(b)))
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "DELETE",
|
||||
URL: ts.URL,
|
||||
Body: []byte(`{"id":"123"}`),
|
||||
@ -259,7 +261,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
_, _ = w.Write([]byte("patch:" + string(b)))
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "PATCH",
|
||||
URL: ts.URL,
|
||||
Body: []byte("data"),
|
||||
@ -275,7 +277,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "HEAD",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
@ -290,7 +292,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
})
|
||||
@ -302,7 +304,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}))
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1,
|
||||
@ -315,7 +317,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}))
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
go func() {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
cancel()
|
||||
@ -337,7 +339,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, dest.URL, http.StatusFound)
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
@ -353,7 +355,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte(r.Header.Get("X-Custom")))
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
Headers: map[string]string{"X-Custom": "myvalue"},
|
||||
@ -376,7 +378,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
// httptest server is on 127.0.0.1 which is not in requiredHosts
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
@ -397,7 +399,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
}))
|
||||
// Allow both servers (both on 127.0.0.1)
|
||||
svc.requiredHosts = []string{"127.0.0.1"}
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
@ -414,7 +416,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
}))
|
||||
// Override requiredHosts to allow the test server
|
||||
svc.requiredHosts = []string{"127.0.0.1"}
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
@ -430,7 +432,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
}))
|
||||
// Allow the test server; redirect to 10.0.0.1 is blocked by allowlist
|
||||
svc.requiredHosts = []string{"127.0.0.1"}
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
@ -474,7 +476,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
}
|
||||
ts.Start()
|
||||
svc.requiredHosts = []string{"127.0.0.1"}
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{Method: "GET", URL: ts.URL, TimeoutMs: 1000})
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{Method: "GET", URL: ts.URL, TimeoutMs: 1000})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(svc.Close()).To(Succeed())
|
||||
Eventually(closed).Should(BeClosed())
|
||||
@ -486,7 +488,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
}))
|
||||
// The literal IP is what authorizes the loopback dial under the private-IP guard.
|
||||
svc.requiredHosts = []string{"*.0.0.1", "127.0.0.1"}
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
@ -497,7 +499,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
|
||||
It("should reject hosts not matching wildcard patterns", func() {
|
||||
svc.requiredHosts = []string{"*.example.com"}
|
||||
_, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
_, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: "http://evil.other.com/test",
|
||||
TimeoutMs: 1000,
|
||||
@ -520,7 +522,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte(oversizedBody))
|
||||
}))
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "GET",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 5000,
|
||||
@ -542,7 +544,7 @@ var _ = Describe("httpServiceImpl", func() {
|
||||
_, _ = w.Write([]byte("method:" + r.Method))
|
||||
}))
|
||||
// Empty method — Go's http.NewRequestWithContext normalizes "" to "GET"
|
||||
resp, err := svc.Send(context.Background(), host.HTTPRequest{
|
||||
resp, err := svc.Send(ctx, host.HTTPRequest{
|
||||
Method: "",
|
||||
URL: ts.URL,
|
||||
TimeoutMs: 1000,
|
||||
|
||||
@ -25,8 +25,8 @@ var _ = Describe("LibraryService", Ordered, func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
DeferCleanup(conf.SnapshotConfig())
|
||||
ctx = context.Background()
|
||||
ds = &tests.MockDataStore{}
|
||||
})
|
||||
|
||||
@ -291,7 +291,6 @@ var _ = Describe("LibraryService", Ordered, func() {
|
||||
// We can't fully test without a real WASM plugin, but we can verify the setup
|
||||
Expect(manager.ds).ToNot(BeNil())
|
||||
|
||||
ctx := context.Background()
|
||||
libs, err := manager.ds.Library().GetAll(adminContext(ctx))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(libs).To(HaveLen(1))
|
||||
|
||||
@ -56,7 +56,7 @@ var _ = Describe("Scrobble Retriever Host Function", Ordered, func() {
|
||||
|
||||
db.Init(ctx)
|
||||
DeferCleanup(func() {
|
||||
Expect(tests.ClearDB()).To(Succeed())
|
||||
Expect(tests.ClearDB(ctx)).To(Succeed())
|
||||
})
|
||||
dataStore = &tests.MockDataStore{RealDS: persistence.New(db.Db())}
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
@ -43,7 +42,7 @@ var _ = Describe("utility functions", Ordered, func() {
|
||||
Describe("GetStoragePath", func() {
|
||||
It("should return the fixed path", func() {
|
||||
impl := storageServiceImpl{}
|
||||
Expect(impl.GetStoragePath(context.TODO())).To(Equal("/storage"))
|
||||
Expect(impl.GetStoragePath(GinkgoT().Context())).To(Equal("/storage"))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ func newTaskQueueService(ctx context.Context, pluginName string, manager *Manage
|
||||
return nil, fmt.Errorf("creating taskqueue schema: %w", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx) //nolint:gosec // cancel is stored in struct and called in Close()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
s := &taskQueueServiceImpl{
|
||||
pluginName: pluginName,
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
|
||||
"encoding/hex"
|
||||
@ -121,7 +120,6 @@ var _ = Describe("WebSocketService", Ordered, func() {
|
||||
It("should allow hosts matching wildcard patterns", func() {
|
||||
// test-websocket manifest allows *.example.com
|
||||
// The pattern *.example.com matches any host ending with .example.com
|
||||
ctx := context.Background()
|
||||
allowed := testService.isHostAllowed("api.example.com")
|
||||
Expect(allowed).To(BeTrue())
|
||||
|
||||
@ -132,7 +130,6 @@ var _ = Describe("WebSocketService", Ordered, func() {
|
||||
// But exact match without subdomain doesn't match *.example.com
|
||||
allowed = testService.isHostAllowed("example.com")
|
||||
Expect(allowed).To(BeFalse())
|
||||
_ = ctx
|
||||
})
|
||||
|
||||
It("should allow exact host matches", func() {
|
||||
|
||||
@ -35,7 +35,7 @@ func purgeCacheBySize(ctx context.Context, dir, maxSize string) {
|
||||
walk := func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
log.Trace(ctx, "Failed to access plugin cache entry", "path", path, err)
|
||||
return nil //nolint:nilerr
|
||||
return nil
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
@ -43,7 +43,7 @@ func purgeCacheBySize(ctx context.Context, dir, maxSize string) {
|
||||
info, err := d.Info()
|
||||
if err != nil {
|
||||
log.Trace(ctx, "Failed to get file info for plugin cache entry", "path", path, err)
|
||||
return nil //nolint:nilerr
|
||||
return nil
|
||||
}
|
||||
files = append(files, fileInfo{
|
||||
path: path,
|
||||
|
||||
@ -36,7 +36,7 @@ var _ = Describe("syncPlugins", func() {
|
||||
It("registers a plugin with a usable ID", func() {
|
||||
writePackage("my-plugin" + PackageExtension)
|
||||
|
||||
Expect(m.syncPlugins(context.Background(), folder)).To(Succeed())
|
||||
Expect(m.syncPlugins(ctx, folder)).To(Succeed())
|
||||
|
||||
_, err := repo.Get(ctx, "my-plugin")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@ -46,7 +46,7 @@ var _ = Describe("syncPlugins", func() {
|
||||
writePackage("." + PackageExtension)
|
||||
writePackage(".." + PackageExtension)
|
||||
|
||||
Expect(m.syncPlugins(context.Background(), folder)).To(Succeed())
|
||||
Expect(m.syncPlugins(ctx, folder)).To(Succeed())
|
||||
|
||||
all, err := repo.GetAll(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -65,9 +64,10 @@ func callSandbox(manager *Manager, input sandboxInput) sandboxOutput {
|
||||
manager.mu.RUnlock()
|
||||
Expect(p).ToNot(BeNil())
|
||||
|
||||
instance, err := p.instance(context.Background())
|
||||
ctx := GinkgoT().Context()
|
||||
instance, err := p.instance(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer instance.Close(context.Background())
|
||||
defer instance.Close(ctx)
|
||||
|
||||
inputBytes, err := json.Marshal(input)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@ -23,11 +23,14 @@ var _ = Describe("Controller", func() {
|
||||
var ds *tests.MockDataStore
|
||||
var ctrl model.Scanner
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
Describe("Status", func() {
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
db.Init(ctx)
|
||||
DeferCleanup(func() { Expect(tests.ClearDB()).To(Succeed()) })
|
||||
DeferCleanup(func() { Expect(tests.ClearDB(ctx)).To(Succeed()) })
|
||||
ds = &tests.MockDataStore{RealDS: persistence.New(db.Db())}
|
||||
ds.MockedProperty = &tests.MockedPropertyRepo{}
|
||||
ctrl = scanner.New(ctx, ds, events.NoopBroker(), playlists.NewPlaylists(ds, artwork.NewUploader(ds)), metrics.NewNoopInstance())
|
||||
@ -66,9 +69,11 @@ var _ = Describe("LockForMaintenance", func() {
|
||||
})
|
||||
|
||||
var _ = Describe("EffectiveFullScan", func() {
|
||||
var ctx context.Context
|
||||
var ds *tests.MockDataStore
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
pid := model.Library{}.EffectivePID()
|
||||
libraries := &tests.MockLibraryRepo{}
|
||||
libraries.SetData(model.Libraries{
|
||||
@ -81,21 +86,21 @@ var _ = Describe("EffectiveFullScan", func() {
|
||||
|
||||
It("detects a library that needs a full rescan for a PID change", func() {
|
||||
targets := []model.ScanTarget{{LibraryID: 3, FolderPath: "."}}
|
||||
Expect(scanner.EffectiveFullScan(GinkgoT().Context(), ds, false, targets)).To(BeTrue())
|
||||
Expect(scanner.EffectiveFullScan(ctx, ds, false, targets)).To(BeTrue())
|
||||
})
|
||||
|
||||
It("detects an interrupted full scan in a targeted library", func() {
|
||||
targets := []model.ScanTarget{{LibraryID: 1, FolderPath: "."}}
|
||||
Expect(scanner.EffectiveFullScan(context.Background(), ds, false, targets)).To(BeTrue())
|
||||
Expect(scanner.EffectiveFullScan(ctx, ds, false, targets)).To(BeTrue())
|
||||
})
|
||||
|
||||
It("detects an interrupted full scan when scanning all libraries", func() {
|
||||
Expect(scanner.EffectiveFullScan(context.Background(), ds, false, nil)).To(BeTrue())
|
||||
Expect(scanner.EffectiveFullScan(ctx, ds, false, nil)).To(BeTrue())
|
||||
})
|
||||
|
||||
It("ignores interrupted full scans in untargeted libraries", func() {
|
||||
targets := []model.ScanTarget{{LibraryID: 2, FolderPath: "."}}
|
||||
Expect(scanner.EffectiveFullScan(context.Background(), ds, false, targets)).To(BeFalse())
|
||||
Expect(scanner.EffectiveFullScan(ctx, ds, false, targets)).To(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
@ -103,8 +108,9 @@ var _ = Describe("GetInstance", func() {
|
||||
It("returns the same controller to every caller", func() {
|
||||
ds := &tests.MockDataStore{}
|
||||
pls := playlists.NewPlaylists(ds, artwork.NewUploader(ds))
|
||||
a := scanner.GetInstance(context.Background(), ds, events.NoopBroker(), pls, metrics.NewNoopInstance())
|
||||
b := scanner.GetInstance(context.Background(), ds, events.NoopBroker(), pls, metrics.NewNoopInstance())
|
||||
ctx := context.WithoutCancel(GinkgoT().Context())
|
||||
a := scanner.GetInstance(ctx, ds, events.NoopBroker(), pls, metrics.NewNoopInstance())
|
||||
b := scanner.GetInstance(ctx, ds, events.NoopBroker(), pls, metrics.NewNoopInstance())
|
||||
Expect(a).To(BeIdenticalTo(b))
|
||||
})
|
||||
})
|
||||
|
||||
@ -157,7 +157,7 @@ func writeTargetsToFile(targets []model.ScanTarget) (string, error) {
|
||||
|
||||
for _, target := range targets {
|
||||
if _, err := fmt.Fprintln(tmpFile, target.String()); err != nil {
|
||||
os.Remove(tmpFile.Name()) //nolint:gosec
|
||||
os.Remove(tmpFile.Name())
|
||||
return "", fmt.Errorf("failed to write to temp file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,13 +10,14 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("IgnoreChecker", func() {
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = GinkgoT().Context()
|
||||
})
|
||||
|
||||
Describe("loadPatternsFromFolder", func() {
|
||||
var ic *IgnoreChecker
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
})
|
||||
|
||||
Context("when .ndignore file does not exist", func() {
|
||||
It("should return empty patterns", func() {
|
||||
@ -87,10 +88,8 @@ var _ = Describe("IgnoreChecker", func() {
|
||||
Describe("Push and Pop", func() {
|
||||
var ic *IgnoreChecker
|
||||
var fsys fstest.MapFS
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
fsys = fstest.MapFS{
|
||||
".ndignore": &fstest.MapFile{Data: []byte("*.txt")},
|
||||
"folder1/.ndignore": &fstest.MapFile{Data: []byte("*.mp3")},
|
||||
@ -194,10 +193,8 @@ var _ = Describe("IgnoreChecker", func() {
|
||||
|
||||
Describe("PushAllParents", func() {
|
||||
var ic *IgnoreChecker
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
fsys := fstest.MapFS{
|
||||
".ndignore": &fstest.MapFile{Data: []byte("root.txt")},
|
||||
"folder1/.ndignore": &fstest.MapFile{Data: []byte("level1.txt")},
|
||||
@ -254,11 +251,6 @@ var _ = Describe("IgnoreChecker", func() {
|
||||
|
||||
Describe("ShouldIgnore", func() {
|
||||
var ic *IgnoreChecker
|
||||
var ctx context.Context
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
})
|
||||
|
||||
Context("with no patterns loaded", func() {
|
||||
It("should not ignore any path", func() {
|
||||
|
||||
@ -25,7 +25,7 @@ var _ = Describe("phaseMissingTracks", func() {
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
ctx = GinkgoT().Context()
|
||||
mr = tests.CreateMockMediaFileRepo()
|
||||
lr = &tests.MockLibraryRepo{}
|
||||
lr.SetData(model.Libraries{{ID: 1, LastScanStartedAt: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)}})
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// nolint:unused
|
||||
package scanner
|
||||
|
||||
import (
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user