MCPcopy
hub / github.com/cli/cli / TestManager_Dispatch

Function TestManager_Dispatch

pkg/cmd/extension/manager_test.go:140–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

138}
139
140func TestManager_Dispatch(t *testing.T) {
141 dataDir := t.TempDir()
142 updateDir := t.TempDir()
143 extDir := filepath.Join(dataDir, "extensions", "gh-hello")
144 extPath := filepath.Join(dataDir, "extensions", "gh-hello", "gh-hello")
145 assert.NoError(t, stubExtension(extPath))
146
147 gc, gcOne := &mockGitClient{}, &mockGitClient{}
148 gc.On("ForRepo", extDir).Return(gcOne).Once()
149
150 m := newTestManager(dataDir, updateDir, nil, gc, nil)
151
152 stdout := &bytes.Buffer{}
153 stderr := &bytes.Buffer{}
154 found, err := m.Dispatch([]string{"hello", "one", "two"}, nil, stdout, stderr)
155 assert.NoError(t, err)
156 assert.True(t, found)
157
158 if runtime.GOOS == "windows" {
159 assert.Equal(t, fmt.Sprintf("[sh -c command \"$@\" -- %s one two]\n", extPath), stdout.String())
160 } else {
161 assert.Equal(t, fmt.Sprintf("[%s one two]\n", extPath), stdout.String())
162 }
163 assert.Equal(t, "", stderr.String())
164
165 gc.AssertExpectations(t)
166 gcOne.AssertExpectations(t)
167}
168
169func TestManager_Dispatch_binary(t *testing.T) {
170 dataDir := t.TempDir()

Callers

nothing calls this directly

Calls 6

stubExtensionFunction · 0.85
newTestManagerFunction · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
DispatchMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected