aboutsummaryrefslogtreecommitdiff
path: root/deadlinks_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'deadlinks_test.go')
-rw-r--r--deadlinks_test.go59
1 files changed, 46 insertions, 13 deletions
diff --git a/deadlinks_test.go b/deadlinks_test.go
index 9556803..a43df3d 100644
--- a/deadlinks_test.go
+++ b/deadlinks_test.go
@@ -38,34 +38,65 @@ func TestMain(m *testing.M) {
}
func TestDeadLinks_Scan(t *testing.T) {
- var testUrl = `http://` + testListenAddress + `/`
+ var testUrl = `http://` + testListenAddress
type testCase struct {
- exp map[string][]deadlinks.Broken
- baseUrl string
+ exp map[string][]deadlinks.Broken
+ scanUrl string
+ expError string
}
listCase := []testCase{{
- baseUrl: testUrl,
+ scanUrl: `127.0.0.1:14594`,
+ expError: `Scan: invalid URL "127.0.0.1:14594"`,
+ }, {
+ scanUrl: `http://127.0.0.1:14594`,
+ expError: `Scan: Get "http://127.0.0.1:14594": dial tcp 127.0.0.1:14594: connect: connection refused`,
+ }, {
+ scanUrl: testUrl,
exp: map[string][]deadlinks.Broken{
testUrl: []deadlinks.Broken{{
- Link: testUrl + `broken.png`,
+ Link: testUrl + `/broken.png`,
Code: http.StatusNotFound,
}, {
- Link: testUrl + `brokenPage`,
+ Link: testUrl + `/brokenPage`,
Code: http.StatusNotFound,
}, {
Link: `https://kilabit.info/brokenPage`,
Code: http.StatusNotFound,
}},
- testUrl + `page2`: []deadlinks.Broken{{
- Link: testUrl + `broken.png`,
+ testUrl + `/page2`: []deadlinks.Broken{{
+ Link: testUrl + `/broken.png`,
Code: http.StatusNotFound,
}, {
- Link: testUrl + `page2/broken/relative`,
+ Link: testUrl + `/page2/broken/relative`,
Code: http.StatusNotFound,
}, {
- Link: testUrl + `page2/broken2.png`,
+ Link: testUrl + `/page2/broken2.png`,
+ Code: http.StatusNotFound,
+ }},
+ },
+ }, {
+ scanUrl: testUrl + `/page2`,
+ exp: map[string][]deadlinks.Broken{
+ testUrl: []deadlinks.Broken{{
+ Link: testUrl + `/broken.png`,
+ Code: http.StatusNotFound,
+ }, {
+ Link: testUrl + `/brokenPage`,
+ Code: http.StatusNotFound,
+ }, {
+ Link: `https://kilabit.info/brokenPage`,
+ Code: http.StatusNotFound,
+ }},
+ testUrl + `/page2`: []deadlinks.Broken{{
+ Link: testUrl + `/broken.png`,
+ Code: http.StatusNotFound,
+ }, {
+ Link: testUrl + `/page2/broken/relative`,
+ Code: http.StatusNotFound,
+ }, {
+ Link: testUrl + `/page2/broken2.png`,
Code: http.StatusNotFound,
}},
},
@@ -76,10 +107,12 @@ func TestDeadLinks_Scan(t *testing.T) {
err error
)
for _, tcase := range listCase {
- result, err = deadlinks.Scan(tcase.baseUrl)
+ result, err = deadlinks.Scan(tcase.scanUrl)
if err != nil {
- t.Fatal(err)
+ test.Assert(t, tcase.scanUrl+` error`,
+ tcase.expError, err.Error())
+ continue
}
- test.Assert(t, tcase.baseUrl, tcase.exp, result.PageLinks)
+ test.Assert(t, tcase.scanUrl, tcase.exp, result.PageLinks)
}
}