package content import ( "testing" "testing/fstest" ) func TestSettingsAreOptionalAndNormalised(t *testing.T) { // A bare site root must still serve, so an absent file is not an error (ADR-0026). got, err := LoadSettings(fstest.MapFS{}) if err != nil || got.Base != "" || got.Title != "" { t.Fatalf("absent site.yaml gave %+v, %v — want the zero value and no error", got, err) } got, err = LoadSettings(fstest.MapFS{ SettingsFile: {Data: []byte("base: https://khosra.example/\ntitle: খসড়া\n")}, }) if err != nil { t.Fatal(err) } if got.Base != "https://khosra.example" { t.Errorf("base = %q — a trailing slash must be trimmed, or every URL doubles it", got.Base) } if got.Title != "খসড়া" { t.Errorf("title = %q", got.Title) } } func TestMalformedSettingsAreAnError(t *testing.T) { // Unlike one bad bundle, which is skipped loudly (ADR-0029), this misconfigures every page, so the // caller treats it as fatal. if _, err := LoadSettings(fstest.MapFS{SettingsFile: {Data: []byte("base: [unclosed\n")}}); err == nil { t.Error("a malformed site.yaml must be an error") } } func TestAbsoluteOnlyPrefixesWhenABaseExists(t *testing.T) { for _, c := range []struct{ base, path, want string }{ {"https://khosra.example", "/posts/hello/", "https://khosra.example/posts/hello/"}, {"", "/posts/hello/", "/posts/hello/"}, } { if got := Absolute(c.base, c.path); got != c.want { t.Errorf("Absolute(%q, %q) = %q, want %q", c.base, c.path, got, c.want) } } }