-
Notifications
You must be signed in to change notification settings - Fork 3
/
crawler_test.go
53 lines (37 loc) · 1.21 KB
/
crawler_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
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"
)
func getTestSitemapXml(domain string) string {
return fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>http://%s/development</loc>
<lastmod>2015-01-04</lastmod>
<changefreq>never</changefreq>
<priority>1.0</priority>
</url>
</urlset>`, domain)
}
func Test_crawl_validSitemap(t *testing.T) {
testContentServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Some Content")
}))
contentServerURL, _ := url.Parse(testContentServer.URL)
defer testContentServer.Close()
testSitemapServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, getTestSitemapXml(contentServerURL.Host))
}))
defer testSitemapServer.Close()
testServerURL, _ := url.Parse(testSitemapServer.URL)
stopTheCrawler := make(chan bool)
crawl(*testServerURL, CrawlOptions{
NumberOfConcurrentRequests: 2,
Timeout: time.Millisecond * 500,
}, stopTheCrawler)
}