test(backup, scrobble, playevents, recsettings, apierror, auth, providers): merge repeated cases (#8299)
release / web (push) Successful in 1m41s
release / go (push) Successful in 2m4s
release / govulncheck (push) Successful in 23s
release / integration (push) Successful in 3m5s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m35s
release / Build signed APK (push) Canceled after 3m53s

- backup: schema coverage's three tests and the three AWS signing
  examples, one table each.
- scrobble: Qualifies' six boundary tests; the ListenBrainz client's
  refusal mapping, twelve tests of the same rule across three calls, one
  table over call x status; the two similarity lookups' success and URL
  tests, one table.
- playevents: the skip rule's three plays share one fixture. Dropped
  TestRecordPlayEnded_SubThreshold_NoEnqueue: the writer only calls
  scrobble.MaybeEnqueue, whose own test and Qualifies' table hold that
  case; the qualifying-play test still proves the writer calls it.
- recsettings: the three tag-scale tests share one database reset.
- apierror: Error() and From, one test each; auth: RequireAdmin's three.
- providers: GetJSON's not-found and transient answers, one table. Its
  two 401 tests expected the same answer with and without
  TreatAuthAsTransient, which changes only the error's text; the table
  says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 15:16:20 -05:00
co-authored by Claude Opus 5.5
parent b6454270b5
commit cfdbfa30e3
9 changed files with 306 additions and 628 deletions
+22 -45
View File
@@ -9,17 +9,17 @@ import (
"testing"
)
func TestError_ErrorString_NoCause(t *testing.T) {
e := &Error{Message: "x"}
if got := e.Error(); got != "x" {
t.Fatalf("Error() = %q, want %q", got, "x")
}
}
func TestError_ErrorString_WithCause(t *testing.T) {
e := &Error{Message: "x", Cause: errors.New("y")}
if got := e.Error(); got != "x: y" {
t.Fatalf("Error() = %q, want %q", got, "x: y")
func TestError_ErrorString(t *testing.T) {
for _, tc := range []struct {
e *Error
want string
}{
{&Error{Message: "x"}, "x"},
{&Error{Message: "x", Cause: errors.New("y")}, "x: y"},
} {
if got := tc.e.Error(); got != tc.want {
t.Errorf("Error() = %q, want %q", got, tc.want)
}
}
}
@@ -36,46 +36,23 @@ func TestError_Unwrap(t *testing.T) {
}
}
func TestFrom_NilReturnsNil(t *testing.T) {
// From turns any error into the answer a handler writes: nil stays nil, an
// *Error (wrapped or not) is kept as it is, and anything else is a 500 that
// keeps the error as its cause for the log.
func TestFrom(t *testing.T) {
if got := From(nil); got != nil {
t.Fatalf("From(nil) = %v, want nil", got)
t.Errorf("From(nil) = %v, want nil", got)
}
}
func TestFrom_PreservesAPIError(t *testing.T) {
orig := NotFound("track")
got := From(orig)
if got != orig {
t.Fatalf("From(orig) returned different pointer: got %p, want %p", got, orig)
if got := From(orig); got != orig {
t.Errorf("From(*Error) = %p, want the same %p", got, orig)
}
}
func TestFrom_PreservesWrappedAPIError(t *testing.T) {
inner := NotFound("track")
wrapped := fmt.Errorf("ctx: %w", inner)
got := From(wrapped)
if got == nil {
t.Fatal("From(wrapped) = nil, want *Error")
if got := From(fmt.Errorf("ctx: %w", orig)); got != orig {
t.Errorf("From(wrapped *Error) = %v, want the *Error it wraps", got)
}
if got.Code != "track_not_found" {
t.Fatalf("got.Code = %q, want %q", got.Code, "track_not_found")
}
}
func TestFrom_WrapsPlainError(t *testing.T) {
plain := errors.New("boom")
got := From(plain)
if got == nil {
t.Fatal("From(plain) = nil, want *Error")
}
if got.Status != 500 {
t.Errorf("Status = %d, want 500", got.Status)
}
if got.Code != "server_error" {
t.Errorf("Code = %q, want %q", got.Code, "server_error")
}
if got.Cause != plain {
t.Errorf("Cause = %v, want %v", got.Cause, plain)
if got := From(plain); got == nil || got.Status != 500 || got.Code != "server_error" || got.Cause != plain {
t.Errorf("From(plain) = %+v, want a 500 server_error caused by it", got)
}
}