X Tutup
Skip to content

Commit 392460b

Browse files
author
vilmibm
committed
WIP switching to stubBinaryExtension
1 parent 541ed3b commit 392460b

File tree

1 file changed

+23
-45
lines changed

1 file changed

+23
-45
lines changed

pkg/cmd/extension/manager_test.go

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ func TestManager_List(t *testing.T) {
6767
}
6868

6969
func TestManager_List_Binary(t *testing.T) {
70+
//tempDir := t.TempDir()
7071
// TODO
72+
7173
}
7274

7375
func TestManager_Dispatch(t *testing.T) {
@@ -206,50 +208,19 @@ func TestManager_Upgrade_NoExtensions(t *testing.T) {
206208
func TestManager_Upgrade_BinaryExtension(t *testing.T) {
207209
tempDir := t.TempDir()
208210

209-
installReg := httpmock.Registry{}
210-
defer installReg.Verify(t)
211-
installClient := http.Client{Transport: &installReg}
212-
213211
io, _, _, _ := iostreams.Test()
214-
m := newTestManager(tempDir, &installClient, io)
215-
repo := ghrepo.NewWithHost("owner", "gh-bin-ext", "example.com")
216-
217-
installReg.Register(
218-
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
219-
httpmock.JSONResponse(
220-
release{
221-
Assets: []releaseAsset{
222-
{
223-
Name: "gh-bin-ext-windows-amd64",
224-
APIURL: "https://example.com/release/cool",
225-
},
226-
},
227-
}))
228-
installReg.Register(
229-
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
230-
httpmock.JSONResponse(
231-
release{
232-
Tag: "v1.0.1",
233-
Assets: []releaseAsset{
234-
{
235-
Name: "gh-bin-ext-windows-amd64",
236-
APIURL: "https://example.com/release/cool",
237-
},
238-
},
239-
}))
240-
installReg.Register(
241-
httpmock.REST("GET", "release/cool"),
242-
httpmock.StringResponse("FAKE BINARY"))
243-
244-
err := m.Install(repo)
245-
assert.NoError(t, err)
246-
247-
upgradeReg := httpmock.Registry{}
248-
defer upgradeReg.Verify(t)
249-
upgradeClient := http.Client{Transport: &upgradeReg}
212+
reg := httpmock.Registry{}
213+
defer reg.Verify(t)
214+
client := http.Client{Transport: &reg}
215+
stubBinaryExtension(filepath.Join(tempDir, "extensions", "gh-bin-ext"), binManifest{
216+
Owner: "owner",
217+
Name: "gh-bin-ext",
218+
Host: "example.com",
219+
Tag: "v1.0.1",
220+
})
250221

251-
um := newTestManager(tempDir, &upgradeClient, io)
252-
upgradeReg.Register(
222+
m := newTestManager(tempDir, &client, io)
223+
reg.Register(
253224
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
254225
httpmock.JSONResponse(
255226
release{
@@ -261,7 +232,7 @@ func TestManager_Upgrade_BinaryExtension(t *testing.T) {
261232
},
262233
},
263234
}))
264-
upgradeReg.Register(
235+
reg.Register(
265236
httpmock.REST("GET", "api/v3/repos/owner/gh-bin-ext/releases/latest"),
266237
httpmock.JSONResponse(
267238
release{
@@ -273,11 +244,11 @@ func TestManager_Upgrade_BinaryExtension(t *testing.T) {
273244
},
274245
},
275246
}))
276-
upgradeReg.Register(
247+
reg.Register(
277248
httpmock.REST("GET", "release/cool2"),
278249
httpmock.StringResponse("FAKE UPGRADED BINARY"))
279250

280-
err = um.Upgrade("bin-ext", false)
251+
err := m.Upgrade("bin-ext", false)
281252
assert.NoError(t, err)
282253

283254
manifest, err := os.ReadFile(filepath.Join(tempDir, "extensions/gh-bin-ext", manifestName))
@@ -500,3 +471,10 @@ func stubLocalExtension(tempDir, path string) error {
500471
}
501472
return f.Close()
502473
}
474+
475+
func stubBinaryExtension(path string, bm binManifest) error {
476+
// TODO make directory
477+
// TODO write manifest file
478+
// TODO write fake binary file
479+
return nil
480+
}

0 commit comments

Comments
 (0)
X Tutup