MCPcopy Create free account
hub / github.com/cli/cli / Test_diffRun

Function Test_diffRun

pkg/cmd/pr/diff/diff_test.go:181–386  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

179}
180
181func Test_diffRun(t *testing.T) {
182 pr := &api.PullRequest{Number: 123, URL: "https://github.com/OWNER/REPO/pull/123"}
183
184 tests := []struct {
185 name string
186 opts DiffOptions
187 notTTY bool
188 wantFields []string
189 wantStdout string
190 wantStderr string
191 wantErr string
192 wantBrowsedURL string
193 httpStubs func(*httpmock.Registry)
194 }{
195 {
196 name: "no color",
197 opts: DiffOptions{
198 SelectorArg: "123",
199 UseColor: false,
200 Patch: false,
201 },
202 wantFields: []string{"number"},
203 wantStdout: fmt.Sprintf(testDiff, "", "", "", ""),
204 httpStubs: func(reg *httpmock.Registry) {
205 stubDiffRequest(reg, "application/vnd.github.v3.diff", fmt.Sprintf(testDiff, "", "", "", ""))
206 },
207 },
208 {
209 name: "with color",
210 opts: DiffOptions{
211 SelectorArg: "123",
212 UseColor: true,
213 Patch: false,
214 },
215 wantFields: []string{"number"},
216 wantStdout: fmt.Sprintf(testDiff, "\x1b[m", "\x1b[1;37m", "\x1b[32m", "\x1b[31m"),
217 httpStubs: func(reg *httpmock.Registry) {
218 stubDiffRequest(reg, "application/vnd.github.v3.diff", fmt.Sprintf(testDiff, "", "", "", ""))
219 },
220 },
221 {
222 name: "patch format",
223 opts: DiffOptions{
224 SelectorArg: "123",
225 UseColor: false,
226 Patch: true,
227 },
228 wantFields: []string{"number"},
229 wantStdout: fmt.Sprintf(testDiff, "", "", "", ""),
230 httpStubs: func(reg *httpmock.Registry) {
231 stubDiffRequest(reg, "application/vnd.github.v3.patch", fmt.Sprintf(testDiff, "", "", "", ""))
232 },
233 },
234 {
235 name: "name only",
236 opts: DiffOptions{
237 SelectorArg: "123",
238 UseColor: false,

Callers

nothing calls this directly

Calls 12

VerifyMethod · 0.95
BrowsedURLMethod · 0.95
TestFunction · 0.92
NewMockFinderFunction · 0.92
NewFunction · 0.92
stubDiffRequestFunction · 0.85
diffRunFunction · 0.85
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
StringMethod · 0.65
ExpectFieldsMethod · 0.45

Tested by

no test coverage detected