add (presently failing) tests for discovering a simple site map

This commit is contained in:
swaits committed 2015-02-15 00:58:01 -08:00
1 parent 249aca229b
commit 5ef46be8c4
2 files changed
+40 -4

No files matched your search

+13
View File
@@ -2,5 +2,18 @@ package main
import ()
// Page is a struct which defines a single page, which URLs (links and assets) it contains
type Page struct {
URL string
Assets []string
Links []string
}
// docrawl begins crawling the site at "url"
func docrawl(url string) []Page {
var result []Page
return result
}
func main() {
}
+27 -4
View File
@@ -44,7 +44,7 @@ func TestServerRunning(t *testing.T) {
resp, err := http.Get(baseURL)
if resp.StatusCode != 200 || err != nil {
fmt.Printf("got %v, err = %v\n", resp.StatusCode, err)
t.Error(err)
t.Fatal(err)
}
}
@@ -53,7 +53,7 @@ func TestBadRequest(t *testing.T) {
resp, err := http.Get(baseURL + "doesnotexist.html")
if resp.StatusCode != 404 || err != nil {
fmt.Printf("got %v, err = %v\n", resp.StatusCode, err)
t.Error("request for non existent file didn't fail properly")
t.Fatal("request for non existent file didn't fail properly")
}
}
@@ -61,7 +61,7 @@ func TestBadRequest(t *testing.T) {
func TestSimpleFetch(t *testing.T) {
body, err := fetch(baseURL + "fetch_test.html")
if err != nil {
t.Error(err)
t.Fatal(err)
}
desired := "<html><head></head><body></body></html>\n"
if body != desired {
@@ -86,7 +86,7 @@ func TestSimpleParse(t *testing.T) {
t.Error(err)
}
if len(matches) != 2 {
t.Error("invalid number of matches in parse")
t.Fatal("invalid number of matches in parse")
}
if matches[0] != "/about.html" {
t.Error("match text is invalid")
@@ -95,3 +95,26 @@ func TestSimpleParse(t *testing.T) {
t.Error("match text is invalid")
}
}
// TestSimpleMap figures out the site map for the site in baseURL
func TestSimpleMap(t *testing.T) {
pages := docrawl(baseURL)
if len(pages) != 1 {
t.Fatal("got wrong number of pages")
}
if pages[0].URL != baseURL {
t.Error("page URL is invalid")
}
if len(pages[0].Assets) != 1 {
t.Fatal("got wrong number of assets")
}
if pages[0].Assets[0] != baseURL+"/assets/image.png" {
t.Error("asset name is incorrect")
}
if len(pages[0].Links) != 1 {
t.Fatal("got wrong number of links")
}
if pages[0].Links[0] != baseURL+"/about.html" {
t.Error("link name is incorrect")
}
}