feat: add source tests for all wrapper sources
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// Package sourcetest provides shared smoke-test helpers for catalogue sources.
|
||||
// Config checks (Name, Lang, ID) always run. Network calls are skipped under -short.
|
||||
package sourcetest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"goyomi/internal/source"
|
||||
)
|
||||
|
||||
// Run verifies source metadata and, unless -short is set, calls GetPopularManga
|
||||
// and GetLatestUpdates (when supported) against the live site.
|
||||
func Run(t *testing.T, s source.CatalogueSource, wantName, wantLang string) {
|
||||
t.Helper()
|
||||
|
||||
if s == nil {
|
||||
t.Fatal("source is nil")
|
||||
}
|
||||
|
||||
if got := s.Name(); got != wantName {
|
||||
t.Errorf("Name() = %q, want %q", got, wantName)
|
||||
}
|
||||
if got := s.Lang(); got != wantLang {
|
||||
t.Errorf("Lang() = %q, want %q", got, wantLang)
|
||||
}
|
||||
if s.ID() == 0 {
|
||||
t.Error("ID() == 0")
|
||||
}
|
||||
|
||||
if testing.Short() {
|
||||
return
|
||||
}
|
||||
|
||||
t.Run("GetPopularManga", func(t *testing.T) {
|
||||
page, err := s.GetPopularManga(1)
|
||||
if err != nil {
|
||||
t.Fatalf("GetPopularManga(1): %v", err)
|
||||
}
|
||||
if len(page.Mangas) == 0 {
|
||||
t.Fatal("GetPopularManga returned 0 results")
|
||||
}
|
||||
for i, m := range page.Mangas {
|
||||
if m.Title == "" {
|
||||
t.Errorf("manga[%d].Title is empty", i)
|
||||
}
|
||||
if m.URL == "" {
|
||||
t.Errorf("manga[%d].URL is empty", i)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if !s.SupportsLatest() {
|
||||
return
|
||||
}
|
||||
|
||||
t.Run("GetLatestUpdates", func(t *testing.T) {
|
||||
page, err := s.GetLatestUpdates(1)
|
||||
if err != nil {
|
||||
t.Fatalf("GetLatestUpdates(1): %v", err)
|
||||
}
|
||||
if len(page.Mangas) == 0 {
|
||||
t.Fatal("GetLatestUpdates returned 0 results")
|
||||
}
|
||||
for i, m := range page.Mangas {
|
||||
if m.Title == "" {
|
||||
t.Errorf("manga[%d].Title is empty", i)
|
||||
}
|
||||
if m.URL == "" {
|
||||
t.Errorf("manga[%d].URL is empty", i)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user