Files
navidrome/server/nativeapi/delete_many_response_test.go
T
Deluan f8ed972e4c chore(lint): add the ctxvariant linter
ctxvariant (tools/ctxvariant, a golangci-lint module plugin built via .custom-gcl.yml) reports a call to F when
FContext or FWithContext takes the same arguments after a leading ctx, plus stdlib calls whose ctx variant is named
differently (http.Get, net.Listen/Dial, DB.Begin, ...). It replaces the migration-only forbidigo SQL rules.
Not noctx: it misses closures in package-level vars (every Ginkgo spec) and packages without a direct import.
Fixes 702 call sites: 658 in tests, 14 in server code, 30 in migrations. The migrations now use ctx-aware calls;
they already ran every other query with the same ctx, so their behavior is the same.
2026-11-17 20:19:10 -05:00

56 lines
1.4 KiB
Go

package nativeapi
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("writeDeleteManyResponse", func() {
var ctx context.Context
BeforeEach(func() {
ctx = GinkgoT().Context()
})
var w *httptest.ResponseRecorder
write := func(ids ...string) map[string]any {
w = httptest.NewRecorder()
writeDeleteManyResponse(w, httptest.NewRequestWithContext(ctx, http.MethodDelete, "/missing", nil), ids)
var body map[string]any
Expect(json.Unmarshal(w.Body.Bytes(), &body)).To(Succeed(), "response body must be valid JSON: %s", w.Body.String())
return body
}
It("returns a single id as an object", func() {
Expect(write("abc123")).To(HaveKeyWithValue("id", "abc123"))
})
It("returns multiple ids as a list", func() {
Expect(write("a", "b")).To(HaveKeyWithValue("ids", ConsistOf("a", "b")))
})
It("stays valid JSON when the id contains a backslash", func() {
Expect(write(`a\`)).To(HaveKeyWithValue("id", `a\`))
})
It("stays valid JSON when the id contains a quote", func() {
Expect(write(`a"b`)).To(HaveKeyWithValue("id", `a"b`))
})
It("does not HTML-escape the id into entities", func() {
Expect(write("a&b")).To(HaveKeyWithValue("id", "a&b"))
})
It("responds 200 with a JSON content type", func() {
write("abc123")
Expect(w.Code).To(Equal(http.StatusOK))
Expect(w.Header().Get("Content-Type")).To(Equal("application/json"))
})
})