diff --git a/main_test.go b/main_test.go index 8a943a0b..8aa43fe6 100644 --- a/main_test.go +++ b/main_test.go @@ -1,6 +1,8 @@ package main import ( + "bytes" + "github.com/avelino/awesome-go/pkg/markdown" "os" "regexp" "sort" @@ -16,8 +18,29 @@ var ( reLinkWithDescription = regexp.MustCompile(`\* \[.*\]\(.*\) - \S.*[\.\!]`) ) +func helpGetReadmeHTML() []byte { + input, err := os.ReadFile(readmePath) + if err != nil { + panic(err) + } + html, err := markdown.ToHTML(input) + if err != nil { + panic(err) + } + return html +} + +func helpBuildQuery() *goquery.Document { + buf := bytes.NewBuffer(helpGetReadmeHTML()) + query, err := goquery.NewDocumentFromReader(buf) + if err != nil { + panic(err) + } + return query +} + func TestAlpha(t *testing.T) { - query := startQuery() + query := helpBuildQuery() query.Find("body > ul").Each(func(i int, s *goquery.Selection) { if i != 0 { // skip content menu @@ -30,7 +53,7 @@ func TestAlpha(t *testing.T) { } func TestDuplicatedLinks(t *testing.T) { - query := startQuery() + query := helpBuildQuery() links := make(map[string]bool, 0) query.Find("body li > a:first-child").Each(func(_ int, s *goquery.Selection) { t.Run(s.Text(), func(t *testing.T) { diff --git a/scripts.go b/scripts.go index 9d185b58..75063bb0 100644 --- a/scripts.go +++ b/scripts.go @@ -1,36 +1,13 @@ package main import ( - "bytes" "fmt" "html/template" "os" - "github.com/PuerkitoBio/goquery" "github.com/avelino/awesome-go/pkg/markdown" ) -func readme() []byte { - input, err := os.ReadFile(readmePath) - if err != nil { - panic(err) - } - html, err := markdown.ToHTML(input) - if err != nil { - panic(err) - } - return html -} - -func startQuery() *goquery.Document { - buf := bytes.NewBuffer(readme()) - query, err := goquery.NewDocumentFromReader(buf) - if err != nil { - panic(err) - } - return query -} - type content struct { Body template.HTML } diff --git a/stale_repositories_test.go b/stale_repositories_test.go index 8bfbd64c..55823aed 100644 --- a/stale_repositories_test.go +++ b/stale_repositories_test.go @@ -215,7 +215,7 @@ func testCommitAge(toRun bool, href string, client *http.Client, staleRepos *[]s return false } func testStaleRepository() { - query := startQuery() + query := helpBuildQuery() var staleRepos []string addressedRepositories := make(map[string]bool) oauth := os.Getenv("OAUTH_TOKEN")