mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-13 11:14:37 -05:00
move test functions to test file
This commit is contained in:
parent
45f2daa07b
commit
82263463a8
3 changed files with 26 additions and 26 deletions
27
main_test.go
27
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) {
|
||||
|
|
23
scripts.go
23
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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue