WIP refactoring

This commit is contained in:
vilmibm 2021-09-20 17:02:34 -05:00
parent af7805af53
commit f5d269ebad
2 changed files with 43 additions and 6 deletions

View file

@ -185,6 +185,7 @@ type BinManifest struct {
Name string
Host string
// TODO I may end up not using this; just thinking ahead to local installs
// TODO track version
Path string
}

View file

@ -12,8 +12,10 @@ import (
"testing"
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/v2/internal/config"
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/httpmock"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
@ -197,25 +199,57 @@ func TestManager_Upgrade_NoExtensions(t *testing.T) {
assert.Equal(t, "", stderr.String())
}
func TestManager_InstallGit(t *testing.T) {
func TestManager_Install_git(t *testing.T) {
tempDir := t.TempDir()
m := newTestManager(tempDir)
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
err := m.InstallGit("https://github.com/owner/gh-some-ext.git", stdout, stderr)
reg := httpmock.Registry{}
defer reg.Verify(t)
client := http.Client{Transport: &reg}
reg.Register(
httpmock.REST("GET", "repos/owner/gh-some-ext/releases/latest"),
httpmock.JSONResponse(
release{
Assets: []releaseAsset{
{
Name: "not-a-binary",
APIURL: "https://example.com/release/cool",
},
},
}))
reg.Register(
httpmock.REST("GET", "repos/owner/gh-some-ext/contents/gh-some-ext"),
httpmock.StringResponse("script"))
io, _, stdout, stderr := iostreams.Test()
repo := ghrepo.New("owner", "gh-some-ext")
err := m.Install(&client, repo, io, config.NewBlankConfig())
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("[git clone https://github.com/owner/gh-some-ext.git %s]\n", filepath.Join(tempDir, "extensions", "gh-some-ext")), stdout.String())
assert.Equal(t, "", stderr.String())
}
func TestManager_InstallBin(t *testing.T) {
func TestManager_Install_binary(t *testing.T) {
repo := ghrepo.NewWithHost("owner", "gh-bin-ext", "example.com")
reg := httpmock.Registry{}
defer reg.Verify(t)
client := http.Client{Transport: &reg}
reg.Register(
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
httpmock.JSONResponse(
release{
Assets: []releaseAsset{
{
Name: "gh-bin-ext-windows-amd64",
APIURL: "https://example.com/release/cool",
},
},
}))
reg.Register(
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
httpmock.JSONResponse(
@ -234,7 +268,9 @@ func TestManager_InstallBin(t *testing.T) {
tempDir := t.TempDir()
m := newTestManager(tempDir)
err := m.InstallBin(&client, repo)
io, _, _, _ := iostreams.Test()
err := m.Install(&client, repo, io, config.NewBlankConfig())
assert.NoError(t, err)
manifest, err := os.ReadFile(filepath.Join(tempDir, "extensions/gh-bin-ext/manifest.yml"))