add tests for GitHub Enterprise more
These tests require GHE environment. Please set following environment variables: - $GITHUB_ENTERPRISE_TOKEN - $GITHUB_ENTERPRISE_BASE_URL - $GITHUB_ENTERPRISE_REPO
This commit is contained in:
parent
89582ba9d1
commit
a8d7262d70
|
@ -3,6 +3,7 @@ package selfupdate
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/blang/semver"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
@ -177,3 +178,37 @@ func TestDetectFromBrokenGitHubEnterpriseURL(t *testing.T) {
|
|||
t.Fatal("Invalid GitHub Enterprise base URL should raise an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectFromGitHubEnterpriseRepo(t *testing.T) {
|
||||
token := os.Getenv("GITHUB_ENTERPRISE_TOKEN")
|
||||
base := os.Getenv("GITHUB_ENTERPRISE_BASE_URL")
|
||||
repo := os.Getenv("GITHUB_ENTERPRISE_REPO")
|
||||
if token == "" {
|
||||
t.Skip("because token for GHE is not found")
|
||||
}
|
||||
if base == "" {
|
||||
t.Skip("because base URL for GHE is not found")
|
||||
}
|
||||
if repo == "" {
|
||||
t.Skip("because repo slug for GHE is not found")
|
||||
}
|
||||
|
||||
up, err := NewUpdater(Config{APIToken: token, EnterpriseBaseURL: base})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r, ok, err := up.DetectLatest(repo)
|
||||
if err != nil {
|
||||
t.Fatal("Fetch failed:", err)
|
||||
}
|
||||
if !ok {
|
||||
t.Fatal(repo, "not found")
|
||||
}
|
||||
if r == nil {
|
||||
t.Fatal("Release not detected")
|
||||
}
|
||||
if !r.Version.Equals(semver.MustParse("1.2.3")) {
|
||||
t.Error("")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -270,3 +270,47 @@ func TestBrokenGitHubEnterpriseURL(t *testing.T) {
|
|||
t.Error("Unexpected error occurred:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateFromGitHubEnterprise(t *testing.T) {
|
||||
token := os.Getenv("GITHUB_ENTERPRISE_TOKEN")
|
||||
base := os.Getenv("GITHUB_ENTERPRISE_BASE_URL")
|
||||
repo := os.Getenv("GITHUB_ENTERPRISE_REPO")
|
||||
if token == "" {
|
||||
t.Skip("because token for GHE is not found")
|
||||
}
|
||||
if base == "" {
|
||||
t.Skip("because base URL for GHE is not found")
|
||||
}
|
||||
if repo == "" {
|
||||
t.Skip("because repo slug for GHE is not found")
|
||||
}
|
||||
|
||||
setupTestBinary()
|
||||
defer teardownTestBinary()
|
||||
|
||||
up, err := NewUpdater(Config{APIToken: token, EnterpriseBaseURL: base})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
latest := semver.MustParse("1.2.3")
|
||||
prev := semver.MustParse("1.2.2")
|
||||
rel, err := up.UpdateCommand("github-release-test", prev, repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if rel.Version.NE(latest) {
|
||||
t.Error("Version is not latest", rel.Version)
|
||||
}
|
||||
|
||||
bytes, err := exec.Command(filepath.FromSlash("./github-release-test")).Output()
|
||||
if err != nil {
|
||||
t.Fatal("Failed to run test binary after update:", err)
|
||||
}
|
||||
|
||||
out := string(bytes)
|
||||
if out != "v1.2.3\n" {
|
||||
t.Error("Output from test binary after update is unexpected:", out)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue