diff options
| author | Shulhan <ms@kilabit.info> | 2025-05-29 15:32:12 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-05-29 15:32:12 +0700 |
| commit | c2561302bddec4596a2582d72c6bc0942fe4c287 (patch) | |
| tree | 8387fde8dbd258de4d5082909e186162960f2222 | |
| parent | b0c320e436ff5cdc70ad38a980a2af2a7f3e5dfd (diff) | |
| download | jarink-c2561302bddec4596a2582d72c6bc0942fe4c287.tar.xz | |
all: add test cases for broken link and invalid URL
| -rw-r--r-- | deadlinks_test.go | 12 | ||||
| -rw-r--r-- | testdata/web/index.html | 5 | ||||
| -rw-r--r-- | worker.go | 8 |
3 files changed, 23 insertions, 2 deletions
diff --git a/deadlinks_test.go b/deadlinks_test.go index 4269e5d..fc088b5 100644 --- a/deadlinks_test.go +++ b/deadlinks_test.go @@ -94,6 +94,12 @@ func TestDeadLinks_Scan(t *testing.T) { }, { Link: testUrl + `/brokenPage`, Code: http.StatusNotFound, + }, { + Link: `http://127.0.0.1:abc`, + Code: 700, + }, { + Link: `http:/127.0.0.1:11836`, + Code: http.StatusNotFound, }}, testUrl + `/broken.html`: []deadlinks.Broken{{ Link: testUrl + `/brokenPage`, @@ -119,6 +125,12 @@ func TestDeadLinks_Scan(t *testing.T) { }, { Link: testUrl + `/brokenPage`, Code: http.StatusNotFound, + }, { + Link: `http://127.0.0.1:abc`, + Code: 700, + }, { + Link: `http:/127.0.0.1:11836`, + Code: http.StatusNotFound, }}, testUrl + `/broken.html`: []deadlinks.Broken{{ Link: testUrl + `/brokenPage`, diff --git a/testdata/web/index.html b/testdata/web/index.html index f4f86d8..a245d07 100644 --- a/testdata/web/index.html +++ b/testdata/web/index.html @@ -7,8 +7,13 @@ SPDX-License-Identifier: GPL-3.0-only <img src="/broken.png" /> <a href="/brokenPage">Broken page</a> <img src="/gopher.png" /> + <img width="200" src="" /> <a href="/page2">Page 2</a> <a href="/broken.html">Broken HTML</a> <a href="http://127.0.0.1:11900">External URL</a> + <!-- Error when fetching with GET --> + <a href="http:/127.0.0.1:11836">Invalid external URL</a> + <!-- Error when parsing URL --> + <a href="http://127.0.0.1:abc">Invalid URL port</a> </body> </html> @@ -121,7 +121,11 @@ func (wrk *worker) scan(linkq linkQueue) { ) httpResp, err = http.Get(linkq.url) if err != nil { - wrk.errq <- err + if linkq.parentUrl == nil { + wrk.errq <- err + } else { + wrk.markDead(linkq, http.StatusNotFound) + } return } defer httpResp.Body.Close() @@ -196,7 +200,7 @@ func (wrk *worker) parseHTML(linkUrl string, body io.Reader) (err error) { return nil } -func (wrk *worker) processLink(rawParentUrl string, val string, kind atom.Atom) { +func (wrk *worker) processLink(rawParentUrl, val string, kind atom.Atom) { if len(val) == 0 { return } |
