MCPcopy
hub / github.com/cli/cli / TestClientShowRefs

Function TestClientShowRefs

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

Source from the content-addressed store, hash-verified

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