sonda/internal/api/http/router_test.go
tgiachi 8160c33960 feat(lidarr): send an artist to Lidarr and see whether it has it
- POST /artists/{id}/lidarr (admin) adds the artist to the admin's own Lidarr by its
  MusicBrainz id, never by name, with the profiles, the folder and the monitor
  option the admin chose. It works for any artist that has an id, also one that
  Sonda only learned of from a list of similar artists. It can be repeated: an artist
  that Lidarr already has changes nothing. Two sends at once go one after the other.
- GET /artists/{id}/lidarr (signed in) says whether Lidarr has the artist and
  monitors it; what stops the answer is a status (disabled, no_id, not_configured,
  error), as for the descriptions.
- It needs the provider switched on and the profiles and folder chosen; a timeout
  says the artist may have been added anyway.
- Spec, contract test and README, which also say that Sonda downloads nothing.
2026-11-12 11:28:15 +01:00

38 lines
1.1 KiB
Go

package httpapi
import (
"strings"
"testing"
"go.uber.org/zap"
)
// A route whose service was never wired panics on its first request, long after the server
// started. NewRouter refuses to build instead, naming what is missing.
func TestNewRouterRefusesAMissingDependency(t *testing.T) {
defer func() {
r := recover()
msg, _ := r.(string)
if !strings.Contains(msg, "CoversJob") {
t.Errorf("recovered %v, want a panic that names the missing CoversJob", r)
}
}()
d := Deps{Logger: zap.NewNop()}
NewRouter(d)
}
func TestNewRouterNamesEveryMissingDependency(t *testing.T) {
missing := missingDeps(Deps{Logger: zap.NewNop()})
for _, want := range []string{"Auth", "Tokens", "Listening", "CoversJob", "ArtistImagesJob", "DescriptionsJob", "Lidarr", "LidarrArtists", "ArtistImages", "About", "Streams"} {
found := false
for _, m := range missing {
found = found || m == want
}
if !found {
t.Errorf("%s is not reported as missing: %v", want, missing)
}
}
if got := missingDeps(Deps{}); len(got) == 0 {
t.Error("an empty Deps has nothing missing")
}
}