Skip to content

Commit f5d269e

Browse files
author
vilmibm
committed
WIP refactoring
1 parent af7805a commit f5d269e

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

pkg/cmd/extension/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ type BinManifest struct {
185185
Name string
186186
Host string
187187
// TODO I may end up not using this; just thinking ahead to local installs
188+
// TODO track version
188189
Path string
189190
}
190191

pkg/cmd/extension/manager_test.go

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212
"testing"
1313

1414
"github.com/MakeNowJust/heredoc"
15+
"github.com/cli/cli/v2/internal/config"
1516
"github.com/cli/cli/v2/internal/ghrepo"
1617
"github.com/cli/cli/v2/pkg/httpmock"
18+
"github.com/cli/cli/v2/pkg/iostreams"
1719
"github.com/stretchr/testify/assert"
1820
"gopkg.in/yaml.v3"
1921
)
@@ -197,25 +199,57 @@ func TestManager_Upgrade_NoExtensions(t *testing.T) {
197199
assert.Equal(t, "", stderr.String())
198200
}
199201

200-
func TestManager_InstallGit(t *testing.T) {
202+
func TestManager_Install_git(t *testing.T) {
201203
tempDir := t.TempDir()
202204
m := newTestManager(tempDir)
203205

204-
stdout := &bytes.Buffer{}
205-
stderr := &bytes.Buffer{}
206-
err := m.InstallGit("https://github.com/owner/gh-some-ext.git", stdout, stderr)
206+
reg := httpmock.Registry{}
207+
defer reg.Verify(t)
208+
client := http.Client{Transport: &reg}
209+
210+
reg.Register(
211+
httpmock.REST("GET", "repos/owner/gh-some-ext/releases/latest"),
212+
httpmock.JSONResponse(
213+
release{
214+
Assets: []releaseAsset{
215+
{
216+
Name: "not-a-binary",
217+
APIURL: "https://example.com/release/cool",
218+
},
219+
},
220+
}))
221+
reg.Register(
222+
httpmock.REST("GET", "repos/owner/gh-some-ext/contents/gh-some-ext"),
223+
httpmock.StringResponse("script"))
224+
225+
io, _, stdout, stderr := iostreams.Test()
226+
227+
repo := ghrepo.New("owner", "gh-some-ext")
228+
229+
err := m.Install(&client, repo, io, config.NewBlankConfig())
207230
assert.NoError(t, err)
208231
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())
209232
assert.Equal(t, "", stderr.String())
210233
}
211234

212-
func TestManager_InstallBin(t *testing.T) {
235+
func TestManager_Install_binary(t *testing.T) {
213236
repo := ghrepo.NewWithHost("owner", "gh-bin-ext", "example.com")
214237

215238
reg := httpmock.Registry{}
216239
defer reg.Verify(t)
217240
client := http.Client{Transport: &reg}
218241

242+
reg.Register(
243+
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
244+
httpmock.JSONResponse(
245+
release{
246+
Assets: []releaseAsset{
247+
{
248+
Name: "gh-bin-ext-windows-amd64",
249+
APIURL: "https://example.com/release/cool",
250+
},
251+
},
252+
}))
219253
reg.Register(
220254
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
221255
httpmock.JSONResponse(
@@ -234,7 +268,9 @@ func TestManager_InstallBin(t *testing.T) {
234268
tempDir := t.TempDir()
235269
m := newTestManager(tempDir)
236270

237-
err := m.InstallBin(&client, repo)
271+
io, _, _, _ := iostreams.Test()
272+
273+
err := m.Install(&client, repo, io, config.NewBlankConfig())
238274
assert.NoError(t, err)
239275

240276
manifest, err := os.ReadFile(filepath.Join(tempDir, "extensions/gh-bin-ext/manifest.yml"))

0 commit comments

Comments
 (0)