1
0
mirror of https://github.com/avelino/awesome-go.git synced 2024-12-12 17:13:58 +00:00
awesome-go/repo_test.go

152 lines
3.3 KiB
Go
Raw Normal View History

package main
import (
"bytes"
"io/ioutil"
"os"
"regexp"
"sort"
"strings"
"testing"
"text/template"
"github.com/PuerkitoBio/goquery"
"github.com/russross/blackfriday"
gfm "github.com/shurcooL/github_flavored_markdown"
)
type content struct {
Body string
}
func TestAlpha(t *testing.T) {
query := startQuery()
query.Find("body > ul").Each(func(_ int, s *goquery.Selection) {
testList(t, s)
})
}
2015-04-23 19:28:54 +00:00
func TestDuplicatedLinks(t *testing.T) {
query := startQuery()
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) {
href, ok := s.Attr("href")
if !ok {
t.Error("expected to have href")
}
2015-04-23 19:28:54 +00:00
if links[href] {
t.Fatalf("duplicated link '%s'", href)
}
2015-04-23 19:28:54 +00:00
links[href] = true
})
2015-04-23 19:28:54 +00:00
})
}
var (
reContainsLink = regexp.MustCompile(`\* \[.*\]\(.*\)`)
reOnlyLink = regexp.MustCompile(`\* \[.*\]\([^()]*\)$`)
End description with dot (#2283) * End description with dot Make sure a description always ends with a dot. * update (#1) * Add me to maintainers list (#2238) * Http clients (#2237) * Remove gorequest This does not really meet the required quality https://goreportcard.com/report/github.com/parnurzeal/gorequest * Add HTTP-Clients category and sling * Add grequests * I suck at pressing ctrl+f * Add Hoverfly API simulation tool (#2214) * Update README.md (#2236) * Add did (#2235) * Add errorx (#2231) * Add errorx * fix errorx description * Remove Florest, no longer exist (#2239) * Add go-zero-width (#2242) * Deprecate Go-AWS-Auth (#2243) * Add huego. Updated README (#2241) * Add Octillery (#2244) * Remove github.com/GeertJohan/yubigo (#2247) * Remove github.com/rcrowley/go-metric (#2246) * Add a link to fastcache (#2249) * Added iso601 (#2250) * Remove mgutz/dat (#2251) * No PR reviews * last Commits on Mar 28, 2017 * Add mole (#2210) * Deprecate github.com/FiloSottile/gvt (#2256) * Deprecate github.com/sevki/graphql (#2257) * Deprecate github.com/gonum/matrix (#2258) * Deprecate github.com/fatih/structs (#2259) * Deprecate github.com/toby3d/go-telegraph (#2260) * Deprecate github.com/mitchellh/goamz (#2261) * Deprecate github.com/franela/goreq (#2262) * Deprecate github.com/facebookgo/httpcontrol (#2263) * Deprecate github.com/markbates/validate (#2264) * Deprecate github.com/codehack/go-relax (#2265) * Deprecate github.com/volatile/core (#2266) * Deprecate github.com/imdario/medeina (#2267) * Deprecate github.com/daryl/zeus (#2268) * Deprecate github.com/mvdan/interfacer (#2269) * Deprecate github.com/GoClipse/goclipse (#2270) * Add gonum (#2273) * Add gonum * add period * Update validate (#2271) * Update validate package * accidentally removed a word, add it again * Update go-telegraph (#2272) * Remove https://github.com/bmizerany/pat (#2252) * Commits on Aug 15, 2017 * PR No reviews * fix project link (#2278) * Add llir/llvm (#2279) * Koazee (#2248) Please check if what you want to add to `awesome-go` list meets [quality standards](https://github.com/avelino/awesome-go/blob/master/CONTRIBUTING.md#quality-standard) before sending pull request. Thanks! **Please provide package links to:** - github.com repo: https://github.com/wesovilabs/koazee - godoc.org: https://godoc.org/github.com/wesovilabs/koazee - goreportcard.com: https://goreportcard.com/report/github.com/wesovilabs/koazee - coverage service link ([cover.run](https://cover.run/), [gocover](http://gocover.io/), [coveralls](https://coveralls.io/) etc.), example: `[![cover.run](https://cover.run/go/github.com/user/repository.svg?style=flat&tag=golang-1.10)](https://cover.run/go?tag=golang-1.10&repo=github.com%2Fuser%2Frepository)` [![codecov](https://codecov.io/gh/wesovilabs/koazee/branch/master/graph/badge.svg)](https://codecov.io/gh/wesovilabs/koazee) Very good coverage **Note**: that new categories can be added only when there are 3 packages or more. **Make sure that you've checked the boxes below before you submit PR:** - [x] I have added my package in alphabetical order. - [x] I have an appropriate description with correct grammar. - [x] I know that this package was not listed before. - [x] I have added godoc link to the repo and to my pull request. - [x] I have added coverage service link to the repo and to my pull request. - [x] I have added goreportcard link to the repo and to my pull request. - [x] I have read [Contribution guidelines](https://github.com/avelino/awesome-go/blob/master/CONTRIBUTING.md#contribution-guidelines), [maintainers note](https://github.com/avelino/awesome-go/blob/master/CONTRIBUTING.md#maintainers) and [Quality standard](https://github.com/avelino/awesome-go/blob/master/CONTRIBUTING.md#quality-standard). Thanks for your PR, you're awesome! :+1: * Allow exclamation mark * updated error message * add various dots * follow-up (#2) * Revert "update (#1)" (#3) This reverts commit 3e410e38c4e2e1c828aec65346a55379e79e0a0f. * Missed some dots
2018-12-14 11:45:07 +00:00
reLinkWithDescription = regexp.MustCompile(`\* \[.*\]\(.*\) - \S.*[\.\!]`)
)
// Test if an entry has description, it must be separated from link with ` - `
func TestSeparator(t *testing.T) {
var matched, containsLink, noDescription bool
input, err := ioutil.ReadFile("./README.md")
if err != nil {
panic(err)
}
lines := strings.Split(string(input), "\n")
for _, line := range lines {
line = strings.Trim(line, " ")
containsLink = reContainsLink.MatchString(line)
if containsLink {
noDescription = reOnlyLink.MatchString(line)
if noDescription {
continue
}
matched = reLinkWithDescription.MatchString(line)
if !matched {
End description with dot (#2283) * End description with dot Make sure a description always ends with a dot. * update (#1) * Add me to maintainers list (#2238) * Http clients (#2237) * Remove gorequest This does not really meet the required quality https://goreportcard.com/report/github.com/parnurzeal/gorequest * Add HTTP-Clients category and sling * Add grequests * I suck at pressing ctrl+f * Add Hoverfly API simulation tool (#2214) * Update README.md (#2236) * Add did (#2235) * Add errorx (#2231) * Add errorx * fix errorx description * Remove Florest, no longer exist (#2239) * Add go-zero-width (#2242) * Deprecate Go-AWS-Auth (#2243) * Add huego. Updated README (#2241) * Add Octillery (#2244) * Remove github.com/GeertJohan/yubigo (#2247) * Remove github.com/rcrowley/go-metric (#2246) * Add a link to fastcache (#2249) * Added iso601 (#2250) * Remove mgutz/dat (#2251) * No PR reviews * last Commits on Mar 28, 2017 * Add mole (#2210) * Deprecate github.com/FiloSottile/gvt (#2256) * Deprecate github.com/sevki/graphql (#2257) * Deprecate github.com/gonum/matrix (#2258) * Deprecate github.com/fatih/structs (#2259) * Deprecate github.com/toby3d/go-telegraph (#2260) * Deprecate github.com/mitchellh/goamz (#2261) * Deprecate github.com/franela/goreq (#2262) * Deprecate github.com/facebookgo/httpcontrol (#2263) * Deprecate github.com/markbates/validate (#2264) * Deprecate github.com/codehack/go-relax (#2265) * Deprecate github.com/volatile/core (#2266) * Deprecate github.com/imdario/medeina (#2267) * Deprecate github.com/daryl/zeus (#2268) * Deprecate github.com/mvdan/interfacer (#2269) * Deprecate github.com/GoClipse/goclipse (#2270) * Add gonum (#2273) * Add gonum * add period * Update validate (#2271) * Update validate package * accidentally removed a word, add it again * Update go-telegraph (#2272) * Remove https://github.com/bmizerany/pat (#2252) * Commits on Aug 15, 2017 * PR No reviews * fix project link (#2278) * Add llir/llvm (#2279) * Koazee (#2248) Please check if what you want to add to `awesome-go` list meets [quality standards](https://github.com/avelino/awesome-go/blob/master/CONTRIBUTING.md#quality-standard) before sending pull request. Thanks! **Please provide package links to:** - github.com repo: https://github.com/wesovilabs/koazee - godoc.org: https://godoc.org/github.com/wesovilabs/koazee - goreportcard.com: https://goreportcard.com/report/github.com/wesovilabs/koazee - coverage service link ([cover.run](https://cover.run/), [gocover](http://gocover.io/), [coveralls](https://coveralls.io/) etc.), example: `[![cover.run](https://cover.run/go/github.com/user/repository.svg?style=flat&tag=golang-1.10)](https://cover.run/go?tag=golang-1.10&repo=github.com%2Fuser%2Frepository)` [![codecov](https://codecov.io/gh/wesovilabs/koazee/branch/master/graph/badge.svg)](https://codecov.io/gh/wesovilabs/koazee) Very good coverage **Note**: that new categories can be added only when there are 3 packages or more. **Make sure that you've checked the boxes below before you submit PR:** - [x] I have added my package in alphabetical order. - [x] I have an appropriate description with correct grammar. - [x] I know that this package was not listed before. - [x] I have added godoc link to the repo and to my pull request. - [x] I have added coverage service link to the repo and to my pull request. - [x] I have added goreportcard link to the repo and to my pull request. - [x] I have read [Contribution guidelines](https://github.com/avelino/awesome-go/blob/master/CONTRIBUTING.md#contribution-guidelines), [maintainers note](https://github.com/avelino/awesome-go/blob/master/CONTRIBUTING.md#maintainers) and [Quality standard](https://github.com/avelino/awesome-go/blob/master/CONTRIBUTING.md#quality-standard). Thanks for your PR, you're awesome! :+1: * Allow exclamation mark * updated error message * add various dots * follow-up (#2) * Revert "update (#1)" (#3) This reverts commit 3e410e38c4e2e1c828aec65346a55379e79e0a0f. * Missed some dots
2018-12-14 11:45:07 +00:00
t.Errorf("expected entry to be in form of `* [link] - description.`, got '%s'", line)
}
}
}
}
func TestGenerateHTML(t *testing.T) {
err := generateHTML()
if err != nil {
t.Errorf("html generate error '%s'", err.Error())
}
}
func testList(t *testing.T, list *goquery.Selection) {
list.Find("ul").Each(func(_ int, items *goquery.Selection) {
testList(t, items)
items.RemoveFiltered("ul")
})
category := list.Prev().Text()
t.Run(category, func(t *testing.T) {
checkAlphabeticOrder(t, list)
})
}
func readme() []byte {
2015-04-14 04:22:56 +00:00
input, err := ioutil.ReadFile("./README.md")
if err != nil {
panic(err)
}
html := append([]byte("<body>"), blackfriday.MarkdownCommon(input)...)
html = append(html, []byte("</body>")...)
return html
}
func startQuery() *goquery.Document {
buf := bytes.NewBuffer(readme())
2015-04-14 04:22:56 +00:00
query, err := goquery.NewDocumentFromReader(buf)
if err != nil {
panic(err)
}
return query
}
func checkAlphabeticOrder(t *testing.T, s *goquery.Selection) {
items := s.Find("li > a:first-child").Map(func(_ int, li *goquery.Selection) string {
return strings.ToLower(li.Text())
})
sorted := make([]string, len(items))
copy(sorted, items)
sort.Strings(sorted)
for k, item := range items {
if item != sorted[k] {
t.Errorf("expected '%s' but actual is '%s'", sorted[k], item)
}
}
if t.Failed() {
t.Logf("expected order is:\n%s", strings.Join(sorted, "\n"))
}
}
func generateHTML() (err error) {
// options
readmePath := "./README.md"
tplPath := "tmpl/tmpl.html"
idxPath := "tmpl/index.html"
input, _ := ioutil.ReadFile(readmePath)
body := string(gfm.Markdown(input))
c := &content{Body: body}
t := template.Must(template.ParseFiles(tplPath))
f, err := os.Create(idxPath)
t.Execute(f, c)
return
}