🧑‍💻 Added TestSite util for tests

This commit is contained in:
Maxim Lebedev 2023-12-09 12:02:33 +06:00
parent 5d3bd2e334
commit c05feef09b
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 36 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package domain
import (
"net/url"
"path"
"path/filepath"
"testing"
"time"
)
@ -29,3 +31,37 @@ func (s Site) LanguagePrefix() string {
func (s Site) IsMultiLingual() bool {
return 1 < len(s.Languages)
}
func TestSite(tb testing.TB) *Site {
tb.Helper()
ru := NewLanguage("ru")
en := NewLanguage("en")
return &Site{
DefaultLanguage: en,
Language: ru,
Languages: []Language{en, ru},
BaseURL: &url.URL{Scheme: "http", Host: "127.0.0.1:3000", Path: "/"},
TimeZone: time.UTC,
File: NewFile(filepath.Join("content", "index.en.md")),
Title: "Testing",
Resources: make([]*Resource, 0),
Params: map[string]any{
"server": map[string]any{
"header": []any{map[string]any{
"path": "/**",
"headers": map[string]any{
"Link": `<https://auth.example.com/>; rel="indieauth-metadata", ` +
`<https://pub.example.com/>; rel="micropub"`,
},
}, map[string]any{
"path": "/foo/bar",
"headers": map[string]any{
"X-Testing": `sample-text`,
},
}},
},
},
}
}