1382c2efd5
go test -json implicitly sets testing.Verbose()=true, so the old guard always printed manga lists through the script. Switched to an env var (SOURCETEST_VERBOSE=1) set by the script only when -v is passed.
89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
// 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 (
|
|
"os"
|
|
"testing"
|
|
|
|
"goyomi/internal/source"
|
|
)
|
|
|
|
var verboseOutput = os.Getenv("SOURCETEST_VERBOSE") == "1"
|
|
|
|
// 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")
|
|
}
|
|
if verboseOutput {
|
|
t.Logf("--- GetPopularManga (%d results) ---", len(page.Mangas))
|
|
for i, m := range page.Mangas {
|
|
t.Logf(" [%d] %-60s %s", i, m.Title, m.URL)
|
|
}
|
|
}
|
|
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")
|
|
}
|
|
if verboseOutput {
|
|
t.Logf("--- GetLatestUpdates (%d results) ---", len(page.Mangas))
|
|
for i, m := range page.Mangas {
|
|
t.Logf(" [%d] %-60s %s", i, m.Title, m.URL)
|
|
}
|
|
}
|
|
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)
|
|
}
|
|
}
|
|
})
|
|
}
|