Skip to content

Commit

Permalink
Fix tests and downloads from GitHub (#47)
Browse files Browse the repository at this point in the history
* Fix broken tests.

`TestBase16Render` needed the third argument - the app name.

Update `TestBase16ColorschemeList_GetBase16Colorscheme` to not rely on
network downloads. Instead, imbed the content of the file from github to
test the parsing.

* Treat non-200 HTTP codes as errors.

GitHub appears to now return a 404 when no GithubToken is specified.
Instead of failing to retrieve and having empty templates or repo lists,
return an error message to the user by propagating the HTTP error code.

* Permit ".yml" YAML files in scheme repositories.

Some schemes, like "vice", use the three-letter file extension.
  • Loading branch information
weslem authored Feb 26, 2021
1 parent 62eca0c commit a7c9c4e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
20 changes: 19 additions & 1 deletion colorscheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,25 @@ func TestBase16ColorschemeList_GetBase16Colorscheme(t *testing.T) {
}

func TestNewBase16Colorscheme(t *testing.T) {
data1, _ := DownloadFileToString("https://raw.githubusercontent.com/atelierbram/base16-atelier-schemes/master/atelier-forest.yaml")
data1 := `scheme: "Atelier Forest"
author: "Bram de Haan (http://atelierbramdehaan.nl)"
base00: "1b1918"
base01: "2c2421"
base02: "68615e"
base03: "766e6b"
base04: "9c9491"
base05: "a8a19f"
base06: "e6e2e0"
base07: "f1efee"
base08: "f22c40"
base09: "df5320"
base0A: "c38418"
base0B: "7b9726"
base0C: "3d97b8"
base0D: "407ee7"
base0E: "6666ea"
base0F: "c33ff3"`

want1 := Base16Colorscheme{
Name: "Atelier Forest",
Author: "Bram de Haan (http://atelierbramdehaan.nl)",
Expand Down
4 changes: 3 additions & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func DownloadFileToString(url string) (string, error) {
return "", err
}
return string(bodyBytes), nil
} else if err == nil {
err = fmt.Errorf("HTTP code %v", resp.StatusCode)
}
return "", err
}
Expand Down Expand Up @@ -79,7 +81,7 @@ func findYAMLinRepo(repoURL string) []GitHubFile {
// Create a list of .yaml files
var colorSchemes []GitHubFile
for _, v := range keys {
re := regexp.MustCompile(".*yaml")
re := regexp.MustCompile(".*ya?ml")
if re.MatchString(v.Name) {
colorSchemes = append(colorSchemes, v)
}
Expand Down
3 changes: 2 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestBase16Render(t *testing.T) {
type args struct {
templ Base16Template
scheme Base16Colorscheme
app string
}
tests := []struct {
name string
Expand All @@ -30,7 +31,7 @@ func TestBase16Render(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Base16Render(tt.args.templ, tt.args.scheme)
Base16Render(tt.args.templ, tt.args.scheme, tt.args.app)
})
}
}
Expand Down

0 comments on commit a7c9c4e

Please sign in to comment.