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
+27 -57
View File
@@ -28,17 +28,33 @@ func TestHTTPClient_GetJSON_Success(t *testing.T) {
}
}
func TestHTTPClient_GetJSON_404IsNotFound(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNotFound)
}))
defer srv.Close()
c := NewHTTPClient(HTTPOptions{Name: "test"})
var out any
err := c.GetJSON(context.Background(), srv.URL, &out)
if !errors.Is(err, ErrNotFound) {
t.Errorf("err = %v, want ErrNotFound", err)
// A 404 settles the lookup as not found; any other failure, including a
// refused key and a body that isn't JSON, is transient and asked again later.
// A 401 is transient with or without TreatAuthAsTransient.
func TestHTTPClient_GetJSON_AnswersNotFoundOrTransient(t *testing.T) {
for _, tc := range []struct {
name string
status int
body string
authAsRetry bool
want error
}{
{"404", http.StatusNotFound, "", false, ErrNotFound},
{"401", http.StatusUnauthorized, "", false, ErrTransient},
{"401 with TreatAuthAsTransient", http.StatusUnauthorized, "", true, ErrTransient},
{"a body that isn't JSON", http.StatusOK, "not json", false, ErrTransient},
} {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(tc.status)
_, _ = w.Write([]byte(tc.body))
}))
c := NewHTTPClient(HTTPOptions{Name: "test", TreatAuthAsTransient: tc.authAsRetry})
var out struct{ Name string }
err := c.GetJSON(context.Background(), srv.URL, &out)
srv.Close()
if !errors.Is(err, tc.want) {
t.Errorf("%s: err = %v, want %v", tc.name, err, tc.want)
}
}
}
@@ -90,52 +106,6 @@ func TestHTTPClient_GetJSON_RetryOn5xxThenExhausted(t *testing.T) {
}
}
func TestHTTPClient_GetJSON_AuthAsTransient(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
}))
defer srv.Close()
c := NewHTTPClient(HTTPOptions{
Name: "test",
TreatAuthAsTransient: true,
})
var out any
err := c.GetJSON(context.Background(), srv.URL, &out)
if !errors.Is(err, ErrTransient) {
t.Errorf("err = %v, want ErrTransient", err)
}
}
func TestHTTPClient_GetJSON_AuthPassthroughByDefault(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
}))
defer srv.Close()
c := NewHTTPClient(HTTPOptions{Name: "test"})
var out any
err := c.GetJSON(context.Background(), srv.URL, &out)
if !errors.Is(err, ErrTransient) {
// 401 is non-2xx so it falls into the generic transient bucket.
t.Errorf("err = %v, want ErrTransient (generic non-2xx)", err)
}
}
func TestHTTPClient_GetJSON_MalformedBody(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`not json`))
}))
defer srv.Close()
c := NewHTTPClient(HTTPOptions{Name: "test"})
var got struct{ Name string }
err := c.GetJSON(context.Background(), srv.URL, &got)
if !errors.Is(err, ErrTransient) {
t.Errorf("err = %v, want ErrTransient", err)
}
}
func TestHTTPClient_GetJSON_ContextCancel(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusServiceUnavailable)