test: unit tests for the writer, News, IndexNow, HTML groups, slugs, lastmod and slots
- XML escaping and namespaces, no priority, the image cap and file names - News window and cap, sources and languages, the publication name - IndexNow batches of 10 000, answer outcomes, keys and the host filter - HTML sitemap group order, tree order and paging - default slugs, the effective type setting, lastmod config, slot edges
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package classes
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/compass"
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
)
|
||||
|
||||
@@ -36,3 +40,63 @@ func TestRealChanges(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestLastmodIgnore pins golem15.sitemap.lastmod_ignore: the default list
|
||||
// when unset, a YAML list or a comma-separated string replacing it (names
|
||||
// trimmed, blanks dropped), and an empty list ignoring nothing.
|
||||
func TestLastmodIgnore(t *testing.T) {
|
||||
keys := func(m map[string]bool) string {
|
||||
out := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
out = append(out, k)
|
||||
}
|
||||
slices.Sort(out)
|
||||
return strings.Join(out, ",")
|
||||
}
|
||||
if got := keys(LastmodIgnore(nil)); got != "created_at,sort_order,updated_at,views" {
|
||||
t.Fatalf("default = %s", got)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
value any
|
||||
want string
|
||||
}{
|
||||
{[]any{"updated_at", " hits ", ""}, "hits,updated_at"},
|
||||
{[]string{"a", "b"}, "a,b"},
|
||||
{" views , rank,,", "rank,views"},
|
||||
{[]any{}, ""},
|
||||
} {
|
||||
cfg := testConfig(t)
|
||||
if err := cfg.Set(LastmodIgnoreConfigKey, tc.value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := keys(LastmodIgnore(cfg)); got != tc.want {
|
||||
t.Errorf("LastmodIgnore(%#v) = %s, want %s", tc.value, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestRebuildDelay pins golem15.sitemap.rebuild_delay_seconds: 60 s when
|
||||
// unset, the value in seconds, and 0 for 0 or a negative value.
|
||||
func TestRebuildDelay(t *testing.T) {
|
||||
if RebuildDelay(nil) != time.Minute || RebuildDelay(testConfig(t)) != time.Minute {
|
||||
t.Fatal("default delay is not 60 s")
|
||||
}
|
||||
for value, want := range map[int]time.Duration{5: 5 * time.Second, 0: 0, -3: 0} {
|
||||
cfg := testConfig(t)
|
||||
if err := cfg.Set(RebuildDelayConfigKey, value); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := RebuildDelay(cfg); got != want {
|
||||
t.Errorf("RebuildDelay(%d) = %s, want %s", value, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testConfig(t *testing.T) *compass.Config {
|
||||
t.Helper()
|
||||
cfg, err := compass.Open(compass.Options{Dir: t.TempDir()})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user