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

Function TestClientShowRefs

git/client_test.go:355–391  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

353}
354
355func TestClientShowRefs(t *testing.T) {
356 tests := []struct {
357 name string
358 cmdExitStatus int
359 cmdStdout string
360 cmdStderr string
361 wantCmdArgs string
362 wantRefs []Ref
363 wantErrorMsg string
364 }{
365 {
366 name: "show refs with one valid ref and one invalid ref",
367 cmdExitStatus: 128,
368 cmdStdout: "9ea76237a557015e73446d33268569a114c0649c refs/heads/valid",
369 cmdStderr: "fatal: 'refs/heads/invalid' - not a valid ref",
370 wantCmdArgs: `path/to/git show-ref --verify -- refs/heads/valid refs/heads/invalid`,
371 wantRefs: []Ref{{
372 Hash: "9ea76237a557015e73446d33268569a114c0649c",
373 Name: "refs/heads/valid",
374 }},
375 wantErrorMsg: "failed to run git: fatal: 'refs/heads/invalid' - not a valid ref",
376 },
377 }
378 for _, tt := range tests {
379 t.Run(tt.name, func(t *testing.T) {
380 cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr)
381 client := Client{
382 GitPath: "path/to/git",
383 commandContext: cmdCtx,
384 }
385 refs, err := client.ShowRefs(context.Background(), []string{"refs/heads/valid", "refs/heads/invalid"})
386 assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " "))
387 assert.EqualError(t, err, tt.wantErrorMsg)
388 assert.Equal(t, tt.wantRefs, refs)
389 })
390 }
391}
392
393func TestClientConfig(t *testing.T) {
394 tests := []struct {

Callers

nothing calls this directly

Calls 5

ShowRefsMethod · 0.95
createCommandContextFunction · 0.85
EqualMethod · 0.80
JoinMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected