-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if URLs are using underscore character
- Loading branch information
1 parent
5c58f87
commit 9a26d06
Showing
7 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package page | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/stjudewashere/seonaut/internal/issues/errors" | ||
"github.com/stjudewashere/seonaut/internal/models" | ||
|
||
"golang.org/x/net/html" | ||
) | ||
|
||
// Returns a report_manager.PageIssueReporter with a callback function that checks | ||
// if URL has undescore characters. | ||
func NewUnderscoreURLReporter() *models.PageIssueReporter { | ||
c := func(pageReport *models.PageReport, htmlNode *html.Node, header *http.Header) bool { | ||
return strings.Contains(pageReport.URL, "_") | ||
} | ||
|
||
return &models.PageIssueReporter{ | ||
ErrorType: errors.ErrorUnderscoreURL, | ||
Callback: c, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package page_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stjudewashere/seonaut/internal/issues/errors" | ||
"github.com/stjudewashere/seonaut/internal/issues/page" | ||
"github.com/stjudewashere/seonaut/internal/models" | ||
|
||
"golang.org/x/net/html" | ||
) | ||
|
||
// Test the UnderscoreURL reporter with an URL that has not an _ character. | ||
// The reporter should not report the issue. | ||
func TestNoUnderscoreURL(t *testing.T) { | ||
pageReport := &models.PageReport{ | ||
URL: "https://example.com/some-url", | ||
Crawled: true, | ||
MediaType: "text/html", | ||
StatusCode: 200, | ||
Title: "not empty description", | ||
} | ||
|
||
reporter := page.NewUnderscoreURLReporter() | ||
if reporter.ErrorType != errors.ErrorUnderscoreURL { | ||
t.Errorf("TestNoIssues: error type is not correct") | ||
} | ||
|
||
reportsIssue := reporter.Callback(pageReport, &html.Node{}, &http.Header{}) | ||
|
||
if reportsIssue == true { | ||
t.Errorf("TestUnderscoreURL: reportsIssue should be false") | ||
} | ||
} | ||
|
||
// Test the UnderscoreURL reporter with an URL that has an _ character. | ||
// The reporter should report the issue. | ||
func TestUnderscoreURL(t *testing.T) { | ||
pageReport := &models.PageReport{ | ||
URL: "https://example.com/some_url", | ||
Crawled: true, | ||
MediaType: "text/html", | ||
StatusCode: 200, | ||
Title: "not empty description", | ||
} | ||
|
||
reporter := page.NewUnderscoreURLReporter() | ||
if reporter.ErrorType != errors.ErrorUnderscoreURL { | ||
t.Errorf("TestNoIssues: error type is not correct") | ||
} | ||
|
||
reportsIssue := reporter.Callback(pageReport, &html.Node{}, &http.Header{}) | ||
|
||
if reportsIssue == false { | ||
t.Errorf("TestUnderscoreURL: reportsIssue should be true") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DELETE FROM issue_types WHERE id = 63; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INSERT INTO issue_types (id, type, priority) VALUES(63, "ERROR_UNDERSCORE_URL", 3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters