-
Notifications
You must be signed in to change notification settings - Fork 3
/
sitemapindex_test.go
62 lines (44 loc) · 1.49 KB
/
sitemapindex_test.go
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
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func Test_getSitemapIndex_NoIndexGiven_ErrorIsReturned(t *testing.T) {
sitemapIndexContent := `la di da`
testSitemapServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, sitemapIndexContent)
}))
defer testSitemapServer.Close()
testServerURL, _ := url.Parse(testSitemapServer.URL)
_, err := getSitemapIndex(*testServerURL, "gargantua bot")
if err == nil {
t.Fail()
t.Logf("getSitemapIndex(%q) should have returned an error", testSitemapServer.URL)
}
}
func Test_getSitemapIndex_IndexExists_IndexIsNotEmpty(t *testing.T) {
sitemapIndexContent := `<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/sitemap.xml</loc>
<lastmod>2016-10-06T11:20:05+00:00</lastmod>
</sitemap>
</sitemapindex>`
testSitemapServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, sitemapIndexContent)
}))
defer testSitemapServer.Close()
testServerURL, _ := url.Parse(testSitemapServer.URL)
sitemapIndex, err := getSitemapIndex(*testServerURL, "gargantua bot")
if err != nil {
t.Fail()
t.Logf("getSitemapIndex(%q) returned %s", testSitemapServer.URL, err)
}
if len(sitemapIndex.Sitemaps) == 0 {
t.Fail()
t.Logf("getSitemapIndex(%q) does not contain any sitemaps", testSitemapServer.URL)
}
}