-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsitemap_test.go
More file actions
106 lines (95 loc) · 2.76 KB
/
sitemap_test.go
File metadata and controls
106 lines (95 loc) · 2.76 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package sitemapgen
import (
"bytes"
"strconv"
"testing"
"time"
)
func TestSitemap_GetXMLOutput(t *testing.T) {
sitemap := CreateSitemap()
for i := 0; i < 4; i++ {
url := CreateUrl("http://test.test/" + strconv.Itoa(i))
if i == 0 {
url.SetChangeFreq(WEEKLY)
url.SetPriority(2)
lastMod := time.Date(2000, 1, 1, 13, 37, 0, 0, time.UTC)
url.SetLastModified(lastMod)
}
sitemap.AddUrl(url)
}
output, err := sitemap.GetXMLOutput()
if err != nil {
t.Error(err.Error())
}
b := []byte(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://test.test/0</loc>
<lastmod>2000-01-01T13:37:00Z</lastmod>
<changefreq>weekly</changefreq>
<priority>1</priority>
</url>
<url>
<loc>http://test.test/1</loc>
</url>
<url>
<loc>http://test.test/2</loc>
</url>
<url>
<loc>http://test.test/3</loc>
</url>
</urlset>`)
if bytes.Compare(b, output) != 0 {
t.Error("Wrong output from GetXMLOutput()")
}
}
func TestSitemap_AddAlternateSupport(t *testing.T) {
sitemap := CreateSitemap()
for i := 0; i < 4; i++ {
url := CreateUrl("http://test.test/" + strconv.Itoa(i))
if i == 0 {
url.SetChangeFreq(WEEKLY)
url.SetPriority(2)
lastMod := time.Date(2000, 1, 1, 13, 37, 0, 0, time.UTC)
url.SetLastModified(lastMod)
}
url.AddAlternate("en", "http://test.test/en/" + strconv.Itoa(i))
url.AddAlternate("sv", "http://test.test/" + strconv.Itoa(i))
sitemap.AddUrl(url)
}
output, err := sitemap.GetXMLOutput()
if err != nil {
t.Error(err.Error())
}
b := []byte(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>http://test.test/0</loc>
<lastmod>2000-01-01T13:37:00Z</lastmod>
<changefreq>weekly</changefreq>
<priority>1</priority>
<xhtml:link rel="alternate" hreflang="en" href="http://test.test/en/0"/>
<xhtml:link rel="alternate" hreflang="sv" href="http://test.test/0"/>
</url>
<url>
<loc>http://test.test/1</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://test.test/en/1"/>
<xhtml:link rel="alternate" hreflang="sv" href="http://test.test/1"/>
</url>
<url>
<loc>http://test.test/2</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://test.test/en/2"/>
<xhtml:link rel="alternate" hreflang="sv" href="http://test.test/2"/>
</url>
<url>
<loc>http://test.test/3</loc>
<xhtml:link rel="alternate" hreflang="en" href="http://test.test/en/3"/>
<xhtml:link rel="alternate" hreflang="sv" href="http://test.test/3"/>
</url>
</urlset>`)
if bytes.Compare(b, output) != 0 {
t.Error("Wrong output from GetXMLOutput()")
}
}