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", "LidarrRequests", "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") } }