Commit 2c34003f authored by Ma_124's avatar Ma_124

improved coverage

parent 0a14e24a
Pipeline #53699855 failed with stages
in 1 minute and 14 seconds
......@@ -415,7 +415,7 @@ before_script:
- $GOPATH/bin/awesome version
script:
- $GOPATH/bin/awesome internal -gitlabci
- $GOPATH/bin/awesome internal -githubci
deploy:
provider: pages
......@@ -436,12 +436,13 @@ deploy:
func mainInternal() {
flag := flagpkg.NewFlagSet("awesome internal", flagpkg.ExitOnError)
gitlab := flag.Bool("gitlabci", false, "Only for internal use.")
github := flag.Bool("githubci", false, "Only for internal use.")
err := flag.Parse(os.Args[2:])
if err != nil {
panic(err)
}
if *gitlab {
if *gitlab || *github {
_, err := os.Stat("pre-build.awesome.sh")
if err == nil {
println("Executing: pre-build.awesome.sh")
......
......@@ -67,7 +67,7 @@ func ExecuteConfig(data []byte, apis *ApisCfg) []error {
for i, l := range cfg.Lists {
for j, out := range l.Outputs {
errs = append(errs, func(i, j int, l *listCfg2, out *outputCfg2) error {
err = func(i, j int, l *listCfg2, out *outputCfg2) error {
iff, err := IFFByName(l.InputFormat)
if err != nil {
return err
......@@ -87,7 +87,11 @@ func ExecuteConfig(data []byte, apis *ApisCfg) []error {
CompileFile(l.InputPath, f, iff, off, apis)
return nil
}(i, j, l, out))
}(i, j, l, out)
if err != nil {
errs = append(errs, err)
}
}
}
......
package awesomefw
import (
"github.com/stretchr/testify/assert"
"math/rand"
"os"
"path/filepath"
"strconv"
"testing"
"time"
)
/*
func TestExecuteConfigFile(t *testing.T) {
in1 := writeTmpFile("in1", `
"# Awesome Awesome
......@@ -49,22 +50,21 @@ For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issu
cfg := writeTmpFile("cfg", `
#!/usr/bin/env awesome compile -config
[[list]]
input="` + in1 + `"
format="tabsep"
[[list.output]]
file="` + out11 + `"
format="test:alpha"
[[list.output]]
file="` + out12 + `"
format="md:table"
[[list]]
input="` + in2 + `"
format="md:list"
[[list.output]]
file="` + out21 + `""
format="tabsep"
lists:
- input: "` + in1 + `"
format: "tabsep"
outputs:
- file: "` + out11 + `"
format: "test:alpha"
- file: "` + out12 + `"
format: "md:table"
- input: "` + in2 + `"
format: "md:list"
outputs:
- file: "` + out21 + `""
format: "tabsep"
# vim: set ts=2 sts=2 sw=2 noet:
`[1:])
......@@ -105,22 +105,79 @@ awesome-sysadmin https://github.com/kahun/awesome-sysadmin Backups, configuratio
`[1:]
errs := ExecuteConfigFile(cfg, NewDebugReqsApisCfg())
/*if errs != nil {
buf := strings.Builder{}
if errs != nil {
for _, err := range errs {
if err == nil {
continue
}
buf.Write([]byte("* " + err.Error() + "\n"))
t.Log("* " + err.Error() + "\n")
}
panic(buf.String())
}*/ /*
errs = errs
panic(errs[0])
}
assert.EqualFileContent(t, out11, expectedOut11)
assert.EqualFileContent(t, out12, expectedOut12)
assert.EqualFileContent(t, out21, expectedOut21)
}*/
}
func TestGetApisFromEnvNormal(t *testing.T) {
const prefix = "AWESOME_TEST_NORMAL_"
err := os.Setenv(prefix + "MAX_GITHUB_REQS", "4000")
if err != nil {
panic(err)
}
err = os.Setenv(prefix + "GITHUB_TOKEN", "S3CR3T")
if err != nil {
panic(err)
}
apis, err := GetApisFromEnv(prefix)
if err != nil {
panic(err)
}
assert.Equal(t, apis.GitHubCfg, &ApiCfg{
"S3CR3T",
4000,
})
}
func TestGetApisFromEnvNoMaxReqs(t *testing.T) {
const prefix = "AWESOME_TEST_NOMAXREQS_"
err := os.Setenv(prefix + "MAX_GITHUB_REQS", "")
if err != nil {
panic(err)
}
err = os.Setenv(prefix + "GITHUB_TOKEN", "S3CR3T")
if err != nil {
panic(err)
}
apis, err := GetApisFromEnv(prefix)
if err != nil {
panic(err)
}
assert.Equal(t, apis.GitHubCfg, &ApiCfg{
"S3CR3T",
6000,
})
}
func TestGetApisFromEnvInvMaxReqs(t *testing.T) {
const prefix = "AWESOME_TEST_INVMAXREQS_"
err := os.Setenv(prefix + "MAX_GITHUB_REQS", "asdasds")
if err != nil {
panic(err)
}
err = os.Setenv(prefix + "GITHUB_TOKEN", "S3CR3T")
if err != nil {
panic(err)
}
_, err = GetApisFromEnv(prefix)
assert.EqualError(t, err, `strconv.Atoi: parsing "asdasds": invalid syntax`)
}
func writeTmpFile(prefix string, content string) string {
path := tmpFile(prefix)
......
......@@ -59,27 +59,28 @@ func FetchMeta(url string, ctx *Ctx) Meta {
* GL Pages
*/
// === GitHub
// === GitHub ===
if strings.HasPrefix(url, "https://github.com/") {
return fetchGitHub(url[19:], ctx)
} else if strings.HasPrefix(url, "http://github.com/") {
return fetchGitHub(url[18:], ctx)
// === GoDoc GitHub
// === GoDoc GitHub ===
} else if strings.HasPrefix(url, "https://godoc.org/github.com/") {
return fetchGitHub(url[29:], ctx)
} else if strings.HasPrefix(url, "http://godoc.org/github.com/") {
return fetchGitHub(url[28:], ctx)
// === GitLab
// === GitLab ===
} else if strings.HasPrefix(url, "https://gitlab.com/") {
return fetchGitLab(strings.Replace(url[19:], "/", "%2F", -1), ctx)
} else if strings.HasPrefix(url, "http://gitlab.com/") {
return fetchGitLab(strings.Replace(url[18:], "/", "%2F", -1), ctx)
// === GoDoc GitLab
// === GoDoc GitLab ===
} else if strings.HasPrefix(url, "https://godoc.org/gitlab.com/") {
return fetchGitLab(strings.Replace(url[29:], "/", "%2F", -1), ctx)
} else if strings.HasPrefix(url, "http://godoc.org/gitlab.com/") {
return fetchGitLab(strings.Replace(url[28:], "/", "%2F", -1), ctx)
} else {
// === Unknown ===
return &naMeta{}
}
}
......@@ -125,14 +126,17 @@ func fetchGitHub(repo string, ctx *Ctx) Meta {
_ = resp.Body.Close()
remaining, _ := strconv.Atoi(resp.Header.Get("X-RateLimit-Remaining"))
if remaining <= 1 {
reset, err := strconv.Atoi(resp.Header.Get("X-RateLimit-Reset"))
if err != nil {
panic(err)
}
remainingS := resp.Header.Get("X-RateLimit-Remaining")
if remainingS != "" {
remaining, _ := strconv.Atoi(remainingS)
if remaining <= 1 {
reset, err := strconv.Atoi(resp.Header.Get("X-RateLimit-Reset"))
if err != nil {
panic(err)
}
println("GitHub: RateLimit: try again at " + time.Unix(int64(reset), 0).In(time.Local).Format("15:04:05"))
println("GitHub: RateLimit: try again at " + time.Unix(int64(reset), 0).In(time.Local).Format("15:04:05"))
}
}
} else {
data = []byte(`{ "stargazers_count": 7654, "forks_count": 32, "open_issues_count": 1, "pushed_at": "2019-01-20T19:24:24Z" }`)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment