Files
summercms/modules/signpost/signpost_test.go
Jakub Zych 490a4e3e6a test(17-06): phase 17 gate with one contract test per layer
- scripts/check-phase17.sh: stages go, plugins, admin, layers, docs and
  postgres across the framework, four plugin repositories, the host and
  both layers; go test -json, vitest JSON and TAP detectors, required
  layer test files, --self-test, --all with NOT RUN postgres and
  PHASE17_REQUIRE_POSTGRES
- TestRegistryDuplicateKey: a duplicate key fails Activate naming both
  plugin IDs, nothing is published
- TestSanitizeByteStable: clean editor HTML comes back byte for byte
2026-10-12 19:03:21 +02:00

47 lines
1.8 KiB
Go

package signpost_test
import (
"strings"
"testing"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/golem15/summercms/modules/signpost"
)
// TestRegistryDuplicateKey pins D-01: two plugins registering the same menu
// item type key fail Activate, the error names the key and both plugin IDs in
// activation order, and nothing is published on the app.
func TestRegistryDuplicateKey(t *testing.T) {
app := smokeApp(t, "")
err := signpost.Activate(app, []typesPlugin{
{id: "acme.blog", types: []pact.MenuItemType{
{Key: "acme-page", DefaultPattern: "/:slug", Resolve: echo},
{Key: "acme-post", DefaultPattern: "/blog/:slug", Resolve: echo},
}},
{id: "acme.news", types: []pact.MenuItemType{{Key: "acme-post", DefaultPattern: "/news/:slug", Resolve: echo}}},
})
if err == nil {
t.Fatal("Activate accepted a duplicate menu item type key")
}
msg := err.Error()
if !strings.HasPrefix(msg, "signpost: ") || !strings.Contains(msg, `"acme-post"`) {
t.Fatalf("error = %q, want the signpost prefix and the key", msg)
}
first, second := strings.Index(msg, "acme.blog"), strings.Index(msg, "acme.news")
if first < 0 || second < 0 || first > second {
t.Fatalf("error = %q, want both plugin IDs, first registrant first", msg)
}
if _, ok := app.Lookup[*signpost.Registry](); ok {
t.Fatal("a registry was published after a failed Activate")
}
// The same key twice inside one plugin is a duplicate too.
err = signpost.Activate(smokeApp(t, ""), []typesPlugin{{id: "acme.blog", types: []pact.MenuItemType{
{Key: "acme-post", DefaultPattern: "/a", Resolve: echo},
{Key: "acme-post", DefaultPattern: "/b", Resolve: echo},
}}})
if err == nil || !strings.Contains(err.Error(), "acme-post") {
t.Fatalf("duplicate inside one plugin: error = %v", err)
}
}