move test functions to test file

This commit is contained in:
Kirill Zhuravlev 2023-02-14 22:55:40 +01:00 committed by Avelino
parent 45f2daa07b
commit 82263463a8
No known key found for this signature in database
GPG Key ID: B345B4D52E98180A
3 changed files with 26 additions and 26 deletions

View File

@ -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) {

View File

@ -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
}

View File

@ -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")