forked from deanishe/awgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,632 additions
and
1,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,16 @@ package update | |
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"reflect" | ||
"testing" | ||
|
||
aw "github.com/deanishe/awgo" | ||
) | ||
|
||
// 6 valid releases, including one prerelease | ||
// v1.0, v2.0, v6.0, v7.1.0-beta, v9.0 (Alfred 4+ only), v10.0-beta | ||
var testGiteaDownloads = []Download{ | ||
// Latest version for Alfred 4 | ||
Download{ | ||
|
@@ -70,21 +73,25 @@ var testGiteaDownloads = []Download{ | |
func TestParseGitea(t *testing.T) { | ||
t.Parallel() | ||
|
||
var ( | ||
data = mustRead("testdata/gitea-releases.json") | ||
dls []Download | ||
err error | ||
) | ||
|
||
src := &giteaSource{ | ||
Repo: "deanishe/alfred-workflow-dummy", | ||
fetch: func(URL string) ([]byte, error) { | ||
return []byte(giteaReleasesEmptyJSON), nil | ||
return ioutil.ReadFile("testdata/empty.json") | ||
}} | ||
dls, err := src.Downloads() | ||
if err != nil { | ||
if dls, err = src.Downloads(); err != nil { | ||
t.Fatal("parse empty JSON") | ||
} | ||
if len(dls) != 0 { | ||
t.Fatal("releases in empty JSON") | ||
} | ||
|
||
dls, err = parseGiteaReleases([]byte(giteaReleasesJSON)) | ||
if err != nil { | ||
if dls, err = parseGiteaReleases(data); err != nil { | ||
t.Fatal("parse Gitea JSON.") | ||
} | ||
if len(dls) != len(testGiteaDownloads) { | ||
|
@@ -101,7 +108,8 @@ func TestParseGitea(t *testing.T) { | |
|
||
func makeGiteaSource() *giteaSource { | ||
src := &giteaSource{Repo: "git.deanishe.net/deanishe/nonexistent"} | ||
dls, err := parseGiteaReleases([]byte(giteaReleasesJSON)) | ||
|
||
dls, err := parseGiteaReleases(mustRead("testdata/gitea-releases.json")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
@@ -201,10 +209,3 @@ func ExampleGitea() { | |
// Output: | ||
// true | ||
} | ||
|
||
var ( | ||
giteaReleasesEmptyJSON = `[]` | ||
// 6 valid releases, including one prerelease | ||
// v1.0, v2.0, v6.0, v7.1.0-beta, v9.0 (Alfred 4+ only), v10.0-beta | ||
giteaReleasesJSON = `[{"id":64612,"tag_name":"v10.0-beta","target_commitish":"master","name":"Latest release (pre-release)","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/64612","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v10.0-beta.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v10.0-beta.zip","draft":false,"prerelease":true,"created_at":"2019-05-03T12:27:30Z","published_at":"2019-05-03T12:27:30Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[{"id":20,"name":"Dummy-10.0-beta.alfredworkflow","size":36063,"download_count":0,"created_at":"2019-05-03T14:46:11Z","uuid":"8c1b2442-eba2-4740-91b3-c57dab219096","browser_download_url":"https://git.deanishe.net/attachments/8c1b2442-eba2-4740-91b3-c57dab219096"}]},{"id":64613,"tag_name":"v9.0","target_commitish":"master","name":"Latest release (Alfred 4)","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/64613","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v9.0.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v9.0.zip","draft":false,"prerelease":false,"created_at":"2019-05-03T12:24:12Z","published_at":"2019-05-03T12:24:12Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[{"id":19,"name":"Dummy-9.0.alfred4workflow","size":36063,"download_count":0,"created_at":"2019-05-03T14:45:38Z","uuid":"acd4dc64-1c85-4d23-b053-711bb4f976c5","browser_download_url":"https://git.deanishe.net/attachments/acd4dc64-1c85-4d23-b053-711bb4f976c5"}]},{"id":61642,"tag_name":"v8point0","target_commitish":"master","name":"Invalid tag (non-semantic)","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/61642","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v8point0.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v8point0.zip","draft":false,"prerelease":false,"created_at":"2018-12-07T16:03:23Z","published_at":"2018-12-07T16:03:23Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[{"id":18,"name":"Dummy-eight.alfredworkflow","size":36063,"download_count":0,"created_at":"2019-04-06T19:03:54Z","uuid":"6b3e403f-4151-4f59-8956-c4a848f36d4b","browser_download_url":"https://git.deanishe.net/attachments/6b3e403f-4151-4f59-8956-c4a848f36d4b"}]},{"id":61643,"tag_name":"v7.1.0-beta","target_commitish":"master","name":"Invalid release (pre-release status)","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/61643","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v7.1.0-beta.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v7.1.0-beta.zip","draft":false,"prerelease":true,"created_at":"2014-10-10T10:58:14Z","published_at":"2014-10-10T10:58:14Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[{"id":17,"name":"Dummy-7.1-beta.alfredworkflow","size":35726,"download_count":0,"created_at":"2019-04-06T19:03:20Z","uuid":"36d70923-d65d-4670-a1c1-adb5d6980b0c","browser_download_url":"https://git.deanishe.net/attachments/36d70923-d65d-4670-a1c1-adb5d6980b0c"}]},{"id":61645,"tag_name":"v7.0","target_commitish":"master","name":"Invalid release (contains no files)","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/61645","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v7.0.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v7.0.zip","draft":false,"prerelease":false,"created_at":"2014-09-14T19:25:55Z","published_at":"2014-09-14T19:25:55Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[]},{"id":61646,"tag_name":"v6.0","target_commitish":"master","name":"Latest valid release","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/61646","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v6.0.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v6.0.zip","draft":false,"prerelease":false,"created_at":"2014-09-14T19:24:41Z","published_at":"2014-09-14T19:24:41Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[{"id":14,"name":"Dummy-6.0.zip","size":36063,"download_count":0,"created_at":"2019-04-06T19:01:30Z","uuid":"683e09ce-5643-456b-82ab-9bd6d8d1bbb8","browser_download_url":"https://git.deanishe.net/attachments/683e09ce-5643-456b-82ab-9bd6d8d1bbb8"},{"id":15,"name":"Dummy-6.0.alfred3workflow","size":36063,"download_count":0,"created_at":"2019-04-06T19:01:30Z","uuid":"eb86751a-7f31-49f0-be4c-1dd1e0557c9d","browser_download_url":"https://git.deanishe.net/attachments/eb86751a-7f31-49f0-be4c-1dd1e0557c9d"},{"id":16,"name":"Dummy-6.0.alfredworkflow","size":36063,"download_count":0,"created_at":"2019-04-06T19:01:30Z","uuid":"61aa34a1-1877-4a41-ae50-01c18c8e2598","browser_download_url":"https://git.deanishe.net/attachments/61aa34a1-1877-4a41-ae50-01c18c8e2598"},{"id":21,"name":"Dummy-6.0.alfred4workflow","size":36063,"download_count":0,"created_at":"2019-05-03T19:28:16Z","uuid":"13392981-721e-4880-b2a9-aad50225d0af","browser_download_url":"https://git.deanishe.net/attachments/13392981-721e-4880-b2a9-aad50225d0af"}]},{"id":61647,"tag_name":"v5.0","target_commitish":"master","name":"Invalid release (contains no files)","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/61647","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v5.0.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v5.0.zip","draft":false,"prerelease":false,"created_at":"2014-09-14T19:22:44Z","published_at":"2014-09-14T19:22:44Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[]},{"id":61648,"tag_name":"v4.0","target_commitish":"master","name":"Invalid release (contains 2 .alfredworkflow files)","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/61648","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v4.0.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v4.0.zip","draft":false,"prerelease":false,"created_at":"2014-09-14T16:34:44Z","published_at":"2014-09-14T16:34:44Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[{"id":12,"name":"Dummy-4.0.alfredworkflow","size":36063,"download_count":0,"created_at":"2019-04-06T19:00:21Z","uuid":"d13764be-c63a-4435-9104-e0df7e1b62c5","browser_download_url":"https://git.deanishe.net/attachments/d13764be-c63a-4435-9104-e0df7e1b62c5"},{"id":13,"name":"Dummy-4.1.alfredworkflow","size":36063,"download_count":0,"created_at":"2019-04-06T19:00:21Z","uuid":"75d6eadf-922e-4179-a179-af703e18f4f6","browser_download_url":"https://git.deanishe.net/attachments/75d6eadf-922e-4179-a179-af703e18f4f6"}]},{"id":61649,"tag_name":"v3.0","target_commitish":"master","name":"Invalid release (no .alfredworkflow file)","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/61649","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v3.0.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v3.0.zip","draft":false,"prerelease":false,"created_at":"2014-09-14T16:34:16Z","published_at":"2014-09-14T16:34:16Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[{"id":11,"name":"Dummy-3.0.zip","size":36063,"download_count":0,"created_at":"2019-04-06T18:59:37Z","uuid":"d6e88cc4-1f2b-4cb2-9749-deb5f6a16e0e","browser_download_url":"https://git.deanishe.net/attachments/d6e88cc4-1f2b-4cb2-9749-deb5f6a16e0e"}]},{"id":61650,"tag_name":"v2.0","target_commitish":"master","name":"v2.0","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/61650","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v2.0.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v2.0.zip","draft":false,"prerelease":false,"created_at":"2014-09-14T16:33:36Z","published_at":"2014-09-14T16:33:36Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[{"id":10,"name":"Dummy-2.0.alfredworkflow","size":36063,"download_count":0,"created_at":"2019-04-06T18:59:08Z","uuid":"03a01b52-93bc-48f0-9b09-37ba212a03fd","browser_download_url":"https://git.deanishe.net/attachments/03a01b52-93bc-48f0-9b09-37ba212a03fd"}]},{"id":61651,"tag_name":"v1.0","target_commitish":"master","name":"v1.0","body":"","url":"https://git.deanishe.net/api/v1/deanishe/alfred-workflow-dummy/releases/61651","tarball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v1.0.tar.gz","zipball_url":"https://git.deanishe.net/deanishe/alfred-workflow-dummy/archive/v1.0.zip","draft":false,"prerelease":false,"created_at":"2014-09-14T16:33:06Z","published_at":"2014-09-14T16:33:06Z","author":{"id":1,"login":"deanishe","full_name":"","email":"[email protected]","avatar_url":"https://secure.gravatar.com/avatar/f8a47e9dc5393dabf96054d4abb76478?d=identicon","language":"en-US","is_admin":true,"username":"deanishe"},"assets":[{"id":9,"name":"Dummy-1.0.alfredworkflow","size":36063,"download_count":0,"created_at":"2019-04-06T18:58:02Z","uuid":"d71ad702-cfce-46ba-aa26-2096d34ff97b","browser_download_url":"https://git.deanishe.net/attachments/d71ad702-cfce-46ba-aa26-2096d34ff97b"}]}]` | ||
) |
Oops, something went wrong.