MCPcopy Index your code
hub / github.com/cli/cli / TestMeReplacer_Replace

Function TestMeReplacer_Replace

pkg/cmd/pr/shared/params_test.go:217–289  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

215}
216
217func TestMeReplacer_Replace(t *testing.T) {
218 rtSuccess := &httpmock.Registry{}
219 rtSuccess.Register(
220 httpmock.GraphQL(`query UserCurrent\b`),
221 httpmock.StringResponse(`
222 { "data": {
223 "viewer": { "login": "ResolvedLogin" }
224 } }
225 `),
226 )
227
228 rtFailure := &httpmock.Registry{}
229 rtFailure.Register(
230 httpmock.GraphQL(`query UserCurrent\b`),
231 httpmock.StatusStringResponse(500, `
232 { "data": {
233 "viewer": { }
234 } }
235 `),
236 )
237
238 type args struct {
239 logins []string
240 client *api.Client
241 repo ghrepo.Interface
242 }
243 tests := []struct {
244 name string
245 args args
246 verify func(t httpmock.Testing)
247 want []string
248 wantErr bool
249 }{
250 {
251 name: "succeeds resolving the userlogin",
252 args: args{
253 client: api.NewClientFromHTTP(&http.Client{Transport: rtSuccess}),
254 repo: ghrepo.New("OWNER", "REPO"),
255 logins: []string{"some", "@me", "other"},
256 },
257 verify: rtSuccess.Verify,
258 want: []string{"some", "ResolvedLogin", "other"},
259 },
260 {
261 name: "fails resolving the userlogin",
262 args: args{
263 client: api.NewClientFromHTTP(&http.Client{Transport: rtFailure}),
264 repo: ghrepo.New("OWNER", "REPO"),
265 logins: []string{"some", "@me", "other"},
266 },
267 verify: rtFailure.Verify,
268 want: []string(nil),
269 wantErr: true,
270 },
271 }
272 for _, tt := range tests {
273 t.Run(tt.name, func(t *testing.T) {
274 me := NewMeReplacer(tt.args.client, tt.args.repo.RepoHost())

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
ReplaceSliceMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
StatusStringResponseFunction · 0.92
NewClientFromHTTPFunction · 0.92
NewFunction · 0.92
NewMeReplacerFunction · 0.85
verifyMethod · 0.80
RunMethod · 0.65
RepoHostMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected