Files
sm-sitemap-plugin/commands_documented_test.go
Jakub Zych e02d0b173f feat: IndexNow key, key file and pings
- saving with IndexNow on generates a 32-hex key (crypto/rand);
  indexnow_new_key generates a new one, so the old key file answers 404
- GET /_sitemap/indexnow/{file} serves <key>.txt as text/plain while
  IndexNow is on; the SEO layer maps it to the site root
- after each rebuild in production the added, changed and removed
  addresses on the site host are queued as golem15.sitemap.indexnow jobs
  (at most 10 000 per request, five attempts)
- the job posts {host, key, urlList} to api.indexnow.org through a
  fetchguard client limited to that host and records the answer; 429 and
  5xx retry, 400, 403 and 422 do not
- the IndexNow tab shows the S2 status partial: key or no key, last
  notification or never, and the 403, 422 and 429 callouts
2026-11-04 12:26:47 +01:00

55 lines
1.7 KiB
Go

package sitemap
import (
"testing"
"git.golem15.com/golem15/sm-sitemap-plugin/classes"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/modules/conga"
"git.golem15.com/golem15/summercms/modules/pact"
)
// TestCommandsDocumented logs every console command whose help lacks a
// description, long help, examples or an option description
// (bonfire.CheckDocs). It only warns: the framework's own coverage test
// fails on a gap, plugin repositories report it.
func TestCommandsDocumented(t *testing.T) {
commands := (&Plugin{}).Commands()
if len(commands) == 0 {
t.Fatal("the plugin declares no commands")
}
for _, problem := range bonfire.CheckDocs(commands) {
t.Logf("%s", problem)
}
}
// TestScheduleAndJobs pins the nightly sitemap:rebuild at 03:00, which must
// name a registered command, the rebuild job (kind golem15.sitemap.rebuild,
// three attempts) and the IndexNow job (golem15.sitemap.indexnow, five).
func TestScheduleAndJobs(t *testing.T) {
p := &Plugin{}
entries := p.Schedule()
if len(entries) != 1 || entries[0].Command != "sitemap:rebuild" || entries[0].Cadence != pact.DailyAt(3, 0) {
t.Fatalf("schedule = %+v", entries)
}
found := false
for _, c := range p.Commands() {
found = found || c.Name == entries[0].Command
}
if !found {
t.Fatal("the scheduled command is not registered")
}
jobs := p.Jobs()
if len(jobs) != 2 {
t.Fatalf("%d jobs", len(jobs))
}
info, ok := conga.Describe(jobs[0])
if !ok || info.Kind != classes.RebuildKind || info.MaxAttempts != 3 {
t.Fatalf("job = %+v %v", info, ok)
}
info, ok = conga.Describe(jobs[1])
if !ok || info.Kind != classes.IndexNowKind || info.MaxAttempts != 5 {
t.Fatalf("job = %+v %v", info, ok)
}
}