Merge pull request 'Implemented basic test functionality' (#1) from feat/test into master

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2026-03-16 23:29:53 +02:00
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
package scraper
import "testing"
func TestShouldVisit(t *testing.T) {
s := New(DefaultConfig())
tests := []struct {
name string
raw string
want bool
}{
{name: "valid wiki page", raw: "https://outward.fandom.com/wiki/Alpha", want: true},
{name: "empty url", raw: "", want: false},
{name: "different domain", raw: "https://example.com/wiki/Alpha", want: false},
{name: "non wiki path", raw: "https://outward.fandom.com/about", want: false},
{name: "ignored exact", raw: "https://outward.fandom.com/wiki/Outward_Wiki", want: false},
{name: "ignored prefix", raw: "https://outward.fandom.com/wiki/File:Logo.png", want: false},
{name: "crafting is allowed", raw: "https://outward.fandom.com/wiki/Crafting", want: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := s.shouldVisit(tt.raw); got != tt.want {
t.Fatalf("shouldVisit(%q) = %v, want %v", tt.raw, got, tt.want)
}
})
}
}
func TestNormalizeImageURL(t *testing.T) {
s := New(DefaultConfig())
got := s.normalizeImageURL("//static.wikia.nocookie.net/outward/images/a/a0/Foo.png/revision/latest/scale-to-width-down/200?cb=1")
want := "https://static.wikia.nocookie.net/outward/images/a/a0/Foo.png/revision/latest?cb=1"
if got != want {
t.Fatalf("normalizeImageURL scaled = %q, want %q", got, want)
}
if got := s.normalizeImageURL(" "); got != "" {
t.Fatalf("normalizeImageURL blank = %q, want empty", got)
}
}
func TestURLAndHeaderHelpers(t *testing.T) {
s := New(DefaultConfig())
if got := s.absoluteWikiURL("/wiki/Alpha"); got != "https://outward.fandom.com/wiki/Alpha" {
t.Fatalf("absoluteWikiURL wiki path = %q", got)
}
if got := s.absoluteWikiURL("https://example.com/x"); got != "https://example.com/x" {
t.Fatalf("absoluteWikiURL absolute = %q", got)
}
if got := s.absoluteWikiURL("mailto:test@example.com"); got != "" {
t.Fatalf("absoluteWikiURL unsupported = %q, want empty", got)
}
if got := s.tableHeaderKey(" ", 2); got != "column_3" {
t.Fatalf("tableHeaderKey blank = %q, want column_3", got)
}
}

4
test.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
go test ./...