Initial commit
This commit is contained in:
commit
e3da3b9c7a
9 changed files with 929 additions and 0 deletions
40
sitemap_test.go
Normal file
40
sitemap_test.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
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")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue