Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package server
|
|
|
|
import (
|
|
"pageswiki/internal/db"
|
|
"pageswiki/internal/store"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCityAutoPlanUsesFixedURLDepthAndMergesDescendants(t *testing.T) {
|
|
database, err := db.Open(filepath.Join(t.TempDir(), "pages.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { database.Close() })
|
|
if err = db.Migrate(database); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
st := store.New(database)
|
|
domain, err := st.GetDefaultDomain()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, p := range []string{"/tech/dev/readme", "/tech/dev/lang/python/page", "/tech/dev/lang/py3/page2"} {
|
|
if _, err = st.CreatePageAtPathInDomain(domain.UUID, p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
srv := &Server{store: st}
|
|
plan, err := srv.buildCityAutoPlan(domain.UUID)
|
|
if err != nil || len(plan) != 3 {
|
|
t.Fatalf("plan=%#v, %v", plan, err)
|
|
}
|
|
if count, err := srv.applyCityAutoPlan(domain.UUID, "actor"); err != nil || count != 3 {
|
|
t.Fatalf("apply count=%d err=%v", count, err)
|
|
}
|
|
city, err := st.GetCityMap(domain.UUID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(city.Quartiers) != 1 || len(city.Quartiers[0].Streets) != 1 || len(city.Quartiers[0].Streets[0].Spots) != 2 {
|
|
t.Fatalf("city=%#v", city)
|
|
}
|
|
for _, spot := range city.Quartiers[0].Streets[0].Spots {
|
|
if spot.Name == "lang" && len(spot.Pages) != 2 {
|
|
t.Fatalf("lang pages=%#v", spot.Pages)
|
|
}
|
|
}
|
|
if err := srv.reconcileCityActivity(domain.UUID); err != nil {
|
|
t.Fatal("event-driven reconcile:", err)
|
|
}
|
|
checkpoint, err := st.ActivityOutboxCheckpoint("city", domain.UUID)
|
|
if err != nil || checkpoint.LastSequence == 0 {
|
|
t.Fatalf("city checkpoint=%+v err=%v", checkpoint, err)
|
|
}
|
|
}
|
|
|
|
func TestCityAutoPlanSameSpotNameInDifferentStreets(t *testing.T) {
|
|
s, _, domain := configFixture(t)
|
|
for _, p := range []string{"/alpha/dev/lang/one", "/beta/dev/lang/two", "/alpha/dev/readme", "/beta/dev/readme"} {
|
|
if _, e := s.store.CreatePageAtPathInDomain(domain, p); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
}
|
|
for i := 0; i < 2; i++ {
|
|
if _, e := s.applyCityAutoPlan(domain, "system:city"); e != nil {
|
|
t.Fatal("reconcile", i, e)
|
|
}
|
|
var spots, names int
|
|
if e := s.store.DB.QueryRow(`SELECT count(*),count(DISTINCT name) FROM spots WHERE domain_uuid=? AND state!='archived'`, domain).Scan(&spots, &names); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if spots != 4 || names != 4 {
|
|
t.Fatal("colliding names merged or duplicated", spots, names)
|
|
}
|
|
}
|
|
}
|