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

Function TestNewGitClient

pkg/cmd/factory/default_test.go:442–478  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

440}
441
442func TestNewGitClient(t *testing.T) {
443 tests := []struct {
444 name string
445 config gh.Config
446 executable string
447 wantAuthHosts []string
448 wantGhPath string
449 }{
450 {
451 name: "creates git client",
452 config: defaultConfig(),
453 executable: filepath.Join("path", "to", "gh"),
454 wantAuthHosts: []string{"nonsense.com"},
455 wantGhPath: filepath.Join("path", "to", "gh"),
456 },
457 }
458 for _, tt := range tests {
459 t.Run(tt.name, func(t *testing.T) {
460 f := &cmdutil.Factory{}
461 f.Config = func() (gh.Config, error) {
462 if tt.config == nil {
463 return config.NewMockConfig(), nil
464 } else {
465 return tt.config, nil
466 }
467 }
468 f.ExecutablePath = tt.executable
469 ios, _, _, _ := iostreams.Test()
470 f.IOStreams = ios
471 c := newGitClient(f)
472 assert.Equal(t, tt.wantGhPath, c.GhPath)
473 assert.Equal(t, ios.In, c.Stdin)
474 assert.Equal(t, ios.Out, c.Stdout)
475 assert.Equal(t, ios.ErrOut, c.Stderr)
476 })
477 }
478}
479
480func defaultConfig() *ghmock.ConfigMock {
481 cfg := config.NewMockConfigFromString("")

Callers

nothing calls this directly

Calls 7

NewMockConfigFunction · 0.92
TestFunction · 0.92
defaultConfigFunction · 0.85
newGitClientFunction · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected