coverage improved from 85.2% to 91.1%
This commit is contained in:
1 parent
e4ce693396
commit
ccc65f9715
6 files changed
+68
-5
No files matched your search
@@ -25,11 +25,6 @@ func docrawl(url string) []*Page {
|
|||||||
}
|
}
|
||||||
delete(queued, destURL)
|
delete(queued, destURL)
|
||||||
|
|
||||||
// skip loop if we already did this URL
|
|
||||||
if _, ok := crawled[dest.URL.String()]; ok {
|
|
||||||
continue // TODO handle
|
|
||||||
}
|
|
||||||
|
|
||||||
// mark this page as complete
|
// mark this page as complete
|
||||||
crawled[dest.URL.String()] = dest
|
crawled[dest.URL.String()] = dest
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestFailedHeaderFetching tests fetchFiletype() to see if we are getting expected failures
|
||||||
|
func TestFailedHeaderFetching(t *testing.T) {
|
||||||
|
page, err := NewPage(nil, "http://doesntexist23492387492837492374982734.com/")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("problem creating New Page struct")
|
||||||
|
}
|
||||||
|
if err := fetchFiletype(page); err == nil {
|
||||||
|
t.Error("tired fetching bogus page but didn't get nil back from fetchFiletype")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestFailedFetching tests fetchFiletype() to see if we are getting expected failures
|
||||||
|
func TestFailedFetching(t *testing.T) {
|
||||||
|
page, err := NewPage(nil, "http://doesntexist23492387492837492374982734.com/")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("problem creating New Page struct")
|
||||||
|
}
|
||||||
|
if _, err := fetchPage(page); err == nil {
|
||||||
|
t.Error("tired fetching bogus page but didn't get nil back from fetchPage")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestBadNewPage tests NewPage to see if we are getting expected failures
|
||||||
|
func TestBadNewPage(t *testing.T) {
|
||||||
|
_, err := NewPage(nil, "h%20t\tp://doesntexist23492387492837492374982734.com/")
|
||||||
|
if err == nil {
|
||||||
|
t.Error("tried creating a NewPage with an invalid URL but didn't get an error")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>About Test</title>
|
||||||
|
<script src="scripts/blah.js"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<img src="/assets/image.png"/>
|
||||||
|
<a href="/">fooey!</a>
|
||||||
|
<a href="http://doesntexist23492387492837492374982734.com/">bad one</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<title>Home</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<img src="/assets/image.png"/>
|
<img src="/assets/image.png"/>
|
||||||
|
|||||||
@@ -52,3 +52,19 @@ func TestURLResolution(t *testing.T) {
|
|||||||
doResolveTest(t, "http://another.com/blah.html", "http://S:D@BaSe.CoM:1/some/crazy/path/index.html?parm=x&blah=foo", "http://aNOThER.CoM/blah.html")
|
doResolveTest(t, "http://another.com/blah.html", "http://S:D@BaSe.CoM:1/some/crazy/path/index.html?parm=x&blah=foo", "http://aNOThER.CoM/blah.html")
|
||||||
doResolveTest(t, "http://empty.com/blah.html", "", "http://empty.com/blah.html")
|
doResolveTest(t, "http://empty.com/blah.html", "", "http://empty.com/blah.html")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestBadResolve tries to resolve bogus URLs to be sure we're getting errors
|
||||||
|
/* TODO not sure how to make url.Parse fail in these cases!!!
|
||||||
|
func TestBadResolve(t* testing.T) {
|
||||||
|
u, err := resolveURL("http://a.com/", "h%20t\tp://doesnte%20xist23492387492837492374982734.com/")
|
||||||
|
if err == nil {
|
||||||
|
t.Logf("got %q", u.String())
|
||||||
|
t.Error("tried resolveURL with an invalid URL but didn't get an error")
|
||||||
|
}
|
||||||
|
u, err = resolveURL("h%20t\tp://doesnte%20xist23492387492837492374982734.com/", "http://a.com/")
|
||||||
|
if err == nil {
|
||||||
|
t.Logf("got %q", u.String())
|
||||||
|
t.Error("tried resolveURL with an invalid URL but didn't get an error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
Reference in new issue
Block a user