Repository: raviqqe/muffet
Pull request #110 (2020-09-27 03:43:48)

Refactor


Patch:
diff --git a/command.go b/command.go
index 59f6a5c..01ca764 100644
--- a/command.go
+++ b/command.go
@@ -92,7 +92,7 @@ func (c *command) runWithError(ss []string) (bool, error) {
 		}
 	}
 
-	checker := newChecker(
+	checker := newPageChecker(
 		f,
 		newLinkValidator(p.URL().Hostname(), rd, sm),
 		args.OnePageOnly,
diff --git a/checker.go b/page_checker.go
similarity index 80%
rename from checker.go
rename to page_checker.go
index f4c854a..a900bb6 100644
--- a/checker.go
+++ b/page_checker.go
@@ -4,7 +4,7 @@ import (
 	"sync"
 )
 
-type checker struct {
+type pageChecker struct {
 	fetcher       *linkFetcher
 	linkValidator *linkValidator
 	daemonManager *daemonManager
@@ -13,8 +13,8 @@ type checker struct {
 	onePageOnly   bool
 }
 
-func newChecker(f *linkFetcher, v *linkValidator, onePageOnly bool) *checker {
-	return &checker{
+func newPageChecker(f *linkFetcher, v *linkValidator, onePageOnly bool) *pageChecker {
+	return &pageChecker{
 		f,
 		v,
 		newDaemonManager(concurrency),
@@ -24,18 +24,18 @@ func newChecker(f *linkFetcher, v *linkValidator, onePageOnly bool) *checker {
 	}
 }
 
-func (c *checker) Results() <-chan *pageResult {
+func (c *pageChecker) Results() <-chan *pageResult {
 	return c.results
 }
 
-func (c *checker) Check(page *page) {
+func (c *pageChecker) Check(page *page) {
 	c.addPage(page)
 	c.daemonManager.Run()
 
 	close(c.results)
 }
 
-func (c *checker) checkPage(p *page) {
+func (c *pageChecker) checkPage(p *page) {
 	us := p.Links()
 
 	sc := make(chan *successLinkResult, len(us))
@@ -87,7 +87,7 @@ func (c *checker) checkPage(p *page) {
 	c.results <- &pageResult{p.URL().String(), ss, es}
 }
 
-func (c *checker) addPage(p *page) {
+func (c *pageChecker) addPage(p *page) {
 	if !c.donePages.Add(p.URL().String()) {
 		c.daemonManager.Add(func() { c.checkPage(p) })
 	}


Test patch:
diff --git a/checker_test.go b/page_checker_test.go
similarity index 80%
rename from checker_test.go
rename to page_checker_test.go
index c3f5833..35f558e 100644
--- a/checker_test.go
+++ b/page_checker_test.go
@@ -8,8 +8,8 @@ import (
 	"github.com/stretchr/testify/assert"
 )
 
-func newTestChecker(c *fakeHTTPClient) *checker {
-	return newChecker(
+func newTestPageChecker(c *fakeHTTPClient) *pageChecker {
+	return newPageChecker(
 		newLinkFetcher(
 			c,
 			newPageParser(newLinkFinder(nil)),
@@ -27,8 +27,8 @@ func newTestPage(t *testing.T, fragments map[string]struct{}, links map[string]e
 	return newPage(u, fragments, links)
 }
 
-func TestCheckerCheckOnePage(t *testing.T) {
-	c := newTestChecker(
+func TestPageCheckerCheckOnePage(t *testing.T) {
+	c := newTestPageChecker(
 		newFakeHTTPClient(
 			func(u *url.URL) (*fakeHTTPResponse, error) {
 				return nil, errors.New("")
@@ -48,8 +48,8 @@ func TestCheckerCheckOnePage(t *testing.T) {
 	assert.Equal(t, 1, i)
 }
 
-func TestCheckerCheckTwoPages(t *testing.T) {
-	c := newTestChecker(
+func TestPageCheckerCheckTwoPages(t *testing.T) {
+	c := newTestPageChecker(
 		newFakeHTTPClient(
 			func(u *url.URL) (*fakeHTTPResponse, error) {
 				s := "http://foo.com/foo"
@@ -77,8 +77,8 @@ func TestCheckerCheckTwoPages(t *testing.T) {
 	assert.Equal(t, 2, i)
 }
 
-func TestCheckerFailToCheckPage(t *testing.T) {
-	c := newTestChecker(
+func TestPageCheckerFailToCheckPage(t *testing.T) {
+	c := newTestPageChecker(
 		newFakeHTTPClient(
 			func(u *url.URL) (*fakeHTTPResponse, error) {
 				return nil, errors.New("")
@@ -93,8 +93,8 @@ func TestCheckerFailToCheckPage(t *testing.T) {
 	assert.False(t, (<-c.Results()).OK())
 }
 
-func TestCheckerDoNotCheckSamePageTwice(t *testing.T) {
-	c := newTestChecker(
+func TestPageCheckerDoNotCheckSamePageTwice(t *testing.T) {
+	c := newTestPageChecker(
 		newFakeHTTPClient(
 			func(u *url.URL) (*fakeHTTPResponse, error) {
 				return newFakeHTTPResponse(200, "http://foo.com", "text/html", nil), nil