MCPcopy
hub / github.com/cli/cli / Test_diffRun

Function Test_diffRun

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

Source from the content-addressed store, hash-verified

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

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
ExpectFieldsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected