- RecordSaved with a change outside golem15.sitemap.lastmod_ignore moves the lastmod of the record's rows (only the changed locale's for a translated change); a no-op save, an ignored change or a rebuild does not - RecordDeleted takes the record's rows out of the files at once - record events queue one rebuild per golem15.sitemap.rebuild_delay_seconds (rebuild_pending_until, P33-12); the job clears it when it starts - sitemap:rebuild [--queue], scheduled nightly at 03:00 (pact.HasSchedule)
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package classes
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
// TestRealChanges pins which saves move lastmod (D-30, RESEARCH Pitfall
|
|
// 4): nothing for an empty or ignored-only change list; every locale for a
|
|
// change on the record's own row; only the named locales for translated
|
|
// changes.
|
|
func TestRealChanges(t *testing.T) {
|
|
ignore := map[string]bool{"updated_at": true, "views": true}
|
|
for name, c := range map[string]struct {
|
|
changes []pact.RecordChange
|
|
any bool
|
|
all bool
|
|
locales []string
|
|
}{
|
|
"no-op save": {nil, false, false, nil},
|
|
"ignored only": {[]pact.RecordChange{{Attribute: "updated_at"}, {Attribute: "views"}}, false, false, nil},
|
|
"own row": {[]pact.RecordChange{{Attribute: "updated_at"}, {Attribute: "title"}}, true, true, nil},
|
|
"translated": {[]pact.RecordChange{{Attribute: "title", Locale: "pl"}, {Attribute: "slug", Locale: "de"}}, true, false, []string{"de", "pl"}},
|
|
"both": {[]pact.RecordChange{{Attribute: "title", Locale: "pl"}, {Attribute: "content"}}, true, true, nil},
|
|
} {
|
|
got := RealChanges(c.changes, ignore)
|
|
if got.Any != c.any || got.All != c.all || len(got.Locales) != len(c.locales) {
|
|
t.Errorf("%s: %+v", name, got)
|
|
continue
|
|
}
|
|
for _, l := range c.locales {
|
|
if !got.Locales[l] {
|
|
t.Errorf("%s: locale %s missing in %+v", name, l, got)
|
|
}
|
|
}
|
|
}
|
|
}
|