-
Notifications
You must be signed in to change notification settings - Fork 3
/
xmlsitemap_test.go
52 lines (36 loc) · 1.16 KB
/
xmlsitemap_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
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func Test_getXMLSitemap_InvalidContent_ErrorIsReturned(t *testing.T) {
testSitemapServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "li da da")
}))
defer testSitemapServer.Close()
testServerURL, _ := url.Parse(testSitemapServer.URL)
_, err := getXMLSitemap(*testServerURL, "gargantua bot")
if err == nil {
t.Fail()
t.Logf("getXMLSitemap(%q) should have returned an error", testSitemapServer.URL)
}
}
func Test_getXMLSitemap_SitemapExists_SitemapIsReturned(t *testing.T) {
testSitemapServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, getTestSitemapXml("example.com"))
}))
defer testSitemapServer.Close()
testServerURL, _ := url.Parse(testSitemapServer.URL)
sitemap, err := getXMLSitemap(*testServerURL,"gargantua bot")
if err != nil {
t.Fail()
t.Logf("getXMLSitemap(%q) returned an error: %s", testSitemapServer.URL, err)
}
if len(sitemap.URLs) == 0 {
t.Fail()
t.Logf("getXMLSitemap(%q) returned 0 URLs", testSitemapServer.URL)
}
}