2017-12-26 02:45:08 +00:00
|
|
|
package selfupdate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/blang/semver"
|
|
|
|
"os"
|
2017-12-26 09:45:52 +00:00
|
|
|
"strings"
|
2017-12-26 02:45:08 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGitHubTokenEnv(t *testing.T) {
|
|
|
|
token := os.Getenv("GITHUB_TOKEN")
|
|
|
|
if token == "" {
|
|
|
|
t.Skip("because $GITHUB_TOKEN is not set")
|
|
|
|
}
|
2017-12-26 03:02:00 +00:00
|
|
|
_ = NewDetector()
|
2017-12-26 02:45:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-26 03:02:00 +00:00
|
|
|
func TestDetectReleaseWithVersionPrefix(t *testing.T) {
|
2017-12-26 09:45:52 +00:00
|
|
|
r, ok, err := DetectLatest("rhysd/github-clone-all")
|
2017-12-26 02:45:08 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Fetch failed:", err)
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("Failed to detect latest")
|
|
|
|
}
|
2017-12-26 09:45:52 +00:00
|
|
|
if r == nil {
|
|
|
|
t.Fatal("Release detected but nil returned for it")
|
|
|
|
}
|
|
|
|
if r.Version.LE(semver.MustParse("2.0.0")) {
|
2017-12-27 03:16:26 +00:00
|
|
|
t.Error("Incorrect version:", r.Version)
|
2017-12-26 09:45:52 +00:00
|
|
|
}
|
|
|
|
if !strings.HasSuffix(r.AssetURL, ".zip") && !strings.HasSuffix(r.AssetURL, ".tar.gz") {
|
2017-12-27 03:16:26 +00:00
|
|
|
t.Error("Incorrect URL for asset:", r.AssetURL)
|
|
|
|
}
|
|
|
|
if r.DocumentURL == "" {
|
|
|
|
t.Error("Document URL should not be empty")
|
|
|
|
}
|
|
|
|
if r.Description == "" {
|
|
|
|
t.Error("Description should not be empty for this repo")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDetectReleaseButNoAsset(t *testing.T) {
|
|
|
|
_, ok, err := DetectLatest("rhysd/clever-f.vim")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Fetch failed:", err)
|
|
|
|
}
|
|
|
|
if ok {
|
|
|
|
t.Fatal("When no asset found, result should be marked as 'not found'")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDetectNoRelease(t *testing.T) {
|
|
|
|
_, ok, err := DetectLatest("rhysd/clever-f.vim")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Fetch failed:", err)
|
|
|
|
}
|
|
|
|
if ok {
|
|
|
|
t.Fatal("When no release found, result should be marked as 'not found'")
|
2017-12-26 02:45:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidSlug(t *testing.T) {
|
2017-12-26 03:02:00 +00:00
|
|
|
d := NewDetector()
|
2017-12-26 02:45:08 +00:00
|
|
|
|
|
|
|
for _, slug := range []string{
|
|
|
|
"foo",
|
|
|
|
"/",
|
|
|
|
"foo/",
|
|
|
|
"/bar",
|
|
|
|
"foo/bar/piyo",
|
|
|
|
} {
|
|
|
|
_, _, err := d.DetectLatest(slug)
|
|
|
|
if err == nil {
|
|
|
|
t.Error(slug, "should be invalid slug")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNonExistingRepo(t *testing.T) {
|
2017-12-26 03:02:00 +00:00
|
|
|
d := NewDetector()
|
2017-12-26 02:45:08 +00:00
|
|
|
v, ok, err := d.DetectLatest("rhysd/non-existing-repo")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Non-existing repo should not cause an error:", v)
|
|
|
|
}
|
|
|
|
if ok {
|
|
|
|
t.Fatal("Release for non-existing repo should not be found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNoReleaseFound(t *testing.T) {
|
2017-12-26 03:02:00 +00:00
|
|
|
d := NewDetector()
|
2017-12-26 02:45:08 +00:00
|
|
|
_, ok, err := d.DetectLatest("rhysd/misc")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Repo having no release should not cause an error:", err)
|
|
|
|
}
|
|
|
|
if ok {
|
|
|
|
t.Fatal("Repo having no release should not be found")
|
|
|
|
}
|
|
|
|
}
|