MCPcopy
hub / github.com/cli/cli / TestNewCmdExtension

Function TestNewCmdExtension

pkg/cmd/extension/command_test.go:29–971  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestNewCmdExtension(t *testing.T) {
30 tempDir := t.TempDir()
31 localExtensionTempDir := filepath.Join(tempDir, "gh-hello")
32 require.NoError(t, os.MkdirAll(localExtensionTempDir, 0755))
33 t.Chdir(localExtensionTempDir)
34
35 tests := []struct {
36 name string
37 args []string
38 managerStubs func(em *extensions.ExtensionManagerMock) func(*testing.T)
39 prompterStubs func(pm *prompter.PrompterMock)
40 httpStubs func(reg *httpmock.Registry)
41 browseStubs func(*browser.Stub) func(*testing.T)
42 isTTY bool
43 wantErr bool
44 errMsg string
45 wantStdout string
46 wantStderr string
47 }{
48 {
49 name: "search for extensions",
50 args: []string{"search"},
51 managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {
52 em.ListFunc = func() []extensions.Extension {
53 return []extensions.Extension{
54 &extensions.ExtensionMock{
55 URLFunc: func() string {
56 return "https://github.com/vilmibm/gh-screensaver"
57 },
58 },
59 &extensions.ExtensionMock{
60 URLFunc: func() string {
61 return "https://github.com/github/gh-gei"
62 },
63 },
64 }
65 }
66 return func(t *testing.T) {
67 listCalls := em.ListCalls()
68 assert.Equal(t, 1, len(listCalls))
69 }
70 },
71 httpStubs: func(reg *httpmock.Registry) {
72 values := url.Values{
73 "page": []string{"1"},
74 "per_page": []string{"30"},
75 "q": []string{"topic:gh-extension"},
76 }
77 reg.Register(
78 httpmock.QueryMatcher("GET", "search/repositories", values),
79 httpmock.JSONResponse(searchResults(4)),
80 )
81 },
82 isTTY: true,
83 wantStdout: "Showing 4 of 4 extensions\n\n REPO DESCRIPTION\n✓ vilmibm/gh-screensaver terminal animations\n cli/gh-cool it's just cool ok\n samcoe/gh-triage helps with triage\n✓ github/gh-gei something something enterprise\n",
84 },
85 {
86 name: "search for extensions non-tty",

Callers

nothing calls this directly

Calls 15

ListCallsMethod · 0.95
RegisterMethod · 0.95
InstallCallsMethod · 0.95
InstallLocalCallsMethod · 0.95
UpgradeCallsMethod · 0.95
EnableDryRunModeCallsMethod · 0.95
RemoveCallsMethod · 0.95
CreateCallsMethod · 0.95
DispatchCallsMethod · 0.95
VerifyMethod · 0.95
QueryMatcherFunction · 0.92
JSONResponseFunction · 0.92

Tested by

no test coverage detected