summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-06-17 23:49:18 +0700
committerShulhan <ms@kilabit.info>2025-06-17 23:49:18 +0700
commit5ac82928702a0f0a7be0ef6e96ab04c39a7e8e9d (patch)
treed323dafb9698ee3b28a68cac4cb9f57239bd0ba1
parent02ff261893e3b27ba6400973cc3202042a8f3f91 (diff)
downloadjarink-5ac82928702a0f0a7be0ef6e96ab04c39a7e8e9d.tar.xz
brokenlinks: add test cases for IgnoreStatus options
There are two test cases, one for invalid status code like "abc", and one for unknown status code like "50".
-rw-r--r--brokenlinks/brokenlinks_test.go18
-rw-r--r--brokenlinks/options.go2
2 files changed, 16 insertions, 4 deletions
diff --git a/brokenlinks/brokenlinks_test.go b/brokenlinks/brokenlinks_test.go
index f52cde9..6feb1e2 100644
--- a/brokenlinks/brokenlinks_test.go
+++ b/brokenlinks/brokenlinks_test.go
@@ -112,7 +112,7 @@ func testInsecureServer(fshandle http.Handler) {
}
}
-func TestBrokenlinks(t *testing.T) {
+func TestScan(t *testing.T) {
var testUrl = `http://` + testAddress
type testCase struct {
@@ -134,6 +134,18 @@ func TestBrokenlinks(t *testing.T) {
}, {
opts: brokenlinks.Options{
Url: testUrl,
+ IgnoreStatus: "abc",
+ },
+ expError: `Scan: Options: invalid status code "abc"`,
+ }, {
+ opts: brokenlinks.Options{
+ Url: testUrl,
+ IgnoreStatus: "50",
+ },
+ expError: `Scan: Options: unknown status code "50"`,
+ }, {
+ opts: brokenlinks.Options{
+ Url: testUrl,
IgnoreStatus: `403`,
Insecure: true,
},
@@ -214,9 +226,9 @@ func TestBrokenlinks(t *testing.T) {
}
}
-// Test running Brokenlinks with file PastResultFile is set.
+// Test scanning with [Options.PastResultFile] is set.
// The PastResultFile is modified to only report errors on "/page2".
-func TestBrokenlinks_pastResult(t *testing.T) {
+func TestScan_pastResult(t *testing.T) {
var testUrl = `http://` + testAddress
type testCase struct {
diff --git a/brokenlinks/options.go b/brokenlinks/options.go
index b4b1f3c..3e69daf 100644
--- a/brokenlinks/options.go
+++ b/brokenlinks/options.go
@@ -59,7 +59,7 @@ func (opts *Options) init() (err error) {
}
if code < http.StatusContinue ||
code > http.StatusNetworkAuthenticationRequired {
- return fmt.Errorf(`%s: status code %s out of range`, logp, val)
+ return fmt.Errorf(`%s: unknown status code %q`, logp, val)
}
opts.ignoreStatus = append(opts.ignoreStatus, int(code))
}