Skip to content

Commit

Permalink
Add option: AllowExternalLinksToFail
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishalya committed Jan 4, 2020
1 parent 57fe7e6 commit 33a1d0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions htmltest/check-link.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (hT *HTMLTest) checkLink(document *htmldoc.Document, node *html.Node) {
}

func (hT *HTMLTest) checkExternal(ref *htmldoc.Reference) {
issueLevel := issues.LevelError
if hT.opts.AllowExternalLinksToFail {
issueLevel = issues.LevelWarning
}
if !hT.opts.CheckExternal {
hT.issueStore.AddIssue(issues.Issue{
Level: issues.LevelDebug,
Expand Down Expand Up @@ -184,15 +188,15 @@ func (hT *HTMLTest) checkExternal(ref *htmldoc.Reference) {
cleanedMessage := strings.TrimPrefix(err.Error(), prefix)
// Add error
hT.issueStore.AddIssue(issues.Issue{
Level: issues.LevelError,
Level: issueLevel,
Message: cleanedMessage,
Reference: ref,
})
return
}
if strings.Contains(err.Error(), "Client.Timeout") {
hT.issueStore.AddIssue(issues.Issue{
Level: issues.LevelError,
Level: issueLevel,
Message: "request exceeded our ExternalTimeout",
Reference: ref,
})
Expand All @@ -213,7 +217,7 @@ func (hT *HTMLTest) checkExternal(ref *htmldoc.Reference) {

// Unhandled client error, return generic error
hT.issueStore.AddIssue(issues.Issue{
Level: issues.LevelError,
Level: issueLevel,
Message: err.Error(),
Reference: ref,
})
Expand Down Expand Up @@ -249,7 +253,7 @@ func (hT *HTMLTest) checkExternal(ref *htmldoc.Reference) {
} else {
// Failed VCRed requests end up here with a status code of zero
hT.issueStore.AddIssue(issues.Issue{
Level: issues.LevelError,
Level: issueLevel,
Message: fmt.Sprintf("%s %d", "Non-OK status:", statusCode),
Reference: ref,
})
Expand Down
4 changes: 4 additions & 0 deletions htmltest/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
// Options struct for htmltest, user and default options are merged and mapped
// into an instance of this struct.
type Options struct {
AllowExternalLinksToFail bool

DirectoryPath string
DirectoryIndex string
FilePath string
Expand Down Expand Up @@ -78,6 +80,8 @@ type Options struct {
func DefaultOptions() map[string]interface{} {
// Specify defaults here
return map[string]interface{}{
"AllowExternalLinksToFail": false,

"DirectoryIndex": "index.html",
"FileExtension": ".html",

Expand Down

0 comments on commit 33a1d0f

Please sign in to comment.