41 lines
970 B
Go
41 lines
970 B
Go
|
package sitemap
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func TestSitemap(t *testing.T) {
|
||
|
urlset := []URL{
|
||
|
URL{
|
||
|
Loc: "https://example.com/",
|
||
|
LastMod: time.Date(2025, time.June, 2, 0, 0, 0, 0, time.UTC),
|
||
|
ChangeFreq: ChangeFreqMonthly,
|
||
|
Priority: 1.0,
|
||
|
},
|
||
|
}
|
||
|
internalURLSet := convertURLs(urlset)
|
||
|
|
||
|
var wr bytes.Buffer
|
||
|
err := parsedTemplate.Execute(&wr, internalURLSet)
|
||
|
if err != nil {
|
||
|
t.Errorf("can't execute template: %v", err)
|
||
|
}
|
||
|
|
||
|
response := wr.String()
|
||
|
if !strings.Contains(response, "<loc>https://example.com/</loc>") {
|
||
|
t.Error("loc tag is missing or invalid")
|
||
|
}
|
||
|
if !strings.Contains(response, "<lastmod>2025-06-02</lastmod>") {
|
||
|
t.Error("lastmod tag is missing or invalid")
|
||
|
}
|
||
|
if !strings.Contains(response, "<changefreq>monthly</changefreq>") {
|
||
|
t.Error("changefreq tag is missing or invalid")
|
||
|
}
|
||
|
if !strings.Contains(response, "<priority>1.0</priority>") {
|
||
|
t.Error("priority tag is missing or invalid")
|
||
|
}
|
||
|
}
|