mirror of
https://github.com/avelino/awesome-go.git
synced 2025-01-31 04:48:53 +00:00
move test functions to test file
This commit is contained in:
parent
45f2daa07b
commit
82263463a8
27
main_test.go
27
main_test.go
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"github.com/avelino/awesome-go/pkg/markdown"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
@ -16,8 +18,29 @@ var (
|
|||||||
reLinkWithDescription = regexp.MustCompile(`\* \[.*\]\(.*\) - \S.*[\.\!]`)
|
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) {
|
func TestAlpha(t *testing.T) {
|
||||||
query := startQuery()
|
query := helpBuildQuery()
|
||||||
query.Find("body > ul").Each(func(i int, s *goquery.Selection) {
|
query.Find("body > ul").Each(func(i int, s *goquery.Selection) {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
// skip content menu
|
// skip content menu
|
||||||
@ -30,7 +53,7 @@ func TestAlpha(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDuplicatedLinks(t *testing.T) {
|
func TestDuplicatedLinks(t *testing.T) {
|
||||||
query := startQuery()
|
query := helpBuildQuery()
|
||||||
links := make(map[string]bool, 0)
|
links := make(map[string]bool, 0)
|
||||||
query.Find("body li > a:first-child").Each(func(_ int, s *goquery.Selection) {
|
query.Find("body li > a:first-child").Each(func(_ int, s *goquery.Selection) {
|
||||||
t.Run(s.Text(), func(t *testing.T) {
|
t.Run(s.Text(), func(t *testing.T) {
|
||||||
|
23
scripts.go
23
scripts.go
@ -1,36 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
|
||||||
"github.com/avelino/awesome-go/pkg/markdown"
|
"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 {
|
type content struct {
|
||||||
Body template.HTML
|
Body template.HTML
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ func testCommitAge(toRun bool, href string, client *http.Client, staleRepos *[]s
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func testStaleRepository() {
|
func testStaleRepository() {
|
||||||
query := startQuery()
|
query := helpBuildQuery()
|
||||||
var staleRepos []string
|
var staleRepos []string
|
||||||
addressedRepositories := make(map[string]bool)
|
addressedRepositories := make(map[string]bool)
|
||||||
oauth := os.Getenv("OAUTH_TOKEN")
|
oauth := os.Getenv("OAUTH_TOKEN")
|
||||||
|
Loading…
Reference in New Issue
Block a user