-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_test.go
More file actions
58 lines (49 loc) · 1.19 KB
/
encode_test.go
File metadata and controls
58 lines (49 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) CattleCloud LLC
// SPDX-License-Identifier: BSD-3-Clause
package sitemaps
import (
"bytes"
"strings"
"testing"
"time"
"github.com/shoenig/test/must"
)
func TestSite_Write(t *testing.T) {
t.Parallel()
unix := time.Date(2025, 10, 31, 9, 15, 0, 0, time.UTC).Unix()
unix2 := time.Date(2025, 2, 21, 16, 30, 0, 0, time.UTC).Unix()
site := make(Site, 0, 2)
site = append(site, &URL{
Location: "/foo/bar",
Modified: EncodeUnix(unix),
Frequency: Daily,
Priority: Bump,
})
site = append(site, &URL{
Location: "/other",
Modified: EncodeUnix(unix2),
Frequency: Weekly,
Priority: None,
})
buf := new(bytes.Buffer)
err := site.Write(buf)
must.NoError(t, err)
exp := strings.TrimSpace(`
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>/foo/bar</loc>
<lastmod>2025-10-31</lastmod>
<changefreq>daily</changefreq>
<priority>0.6</priority>
</url>
<url>
<loc>/other</loc>
<lastmod>2025-02-21</lastmod>
<changefreq>weekly</changefreq>
<priority>0.1</priority>
</url>
</urlset>`)
result := strings.TrimSpace(buf.String())
must.Eq(t, exp, result)
}