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

Function TestNewGitClient

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

Source from the content-addressed store, hash-verified

501}
502
503func TestNewGitClient(t *testing.T) {
504 tests := []struct {
505 name string
506 config gh.Config
507 executable string
508 wantAuthHosts []string
509 wantGhPath string
510 }{
511 {
512 name: "creates git client",
513 config: defaultConfig(),
514 executable: filepath.Join("path", "to", "gh"),
515 wantAuthHosts: []string{"nonsense.com"},
516 wantGhPath: filepath.Join("path", "to", "gh"),
517 },
518 }
519 for _, tt := range tests {
520 t.Run(tt.name, func(t *testing.T) {
521 f := &cmdutil.Factory{}
522 f.Config = func() (gh.Config, error) {
523 if tt.config == nil {
524 return config.NewMockConfig(), nil
525 } else {
526 return tt.config, nil
527 }
528 }
529 f.ExecutablePath = tt.executable
530 ios, _, _, _ := iostreams.Test()
531 f.IOStreams = ios
532 c := newGitClient(f)
533 assert.Equal(t, tt.wantGhPath, c.GhPath)
534 assert.Equal(t, ios.In, c.Stdin)
535 assert.Equal(t, ios.Out, c.Stdout)
536 assert.Equal(t, ios.ErrOut, c.Stderr)
537 })
538 }
539}
540
541func defaultConfig() *ghmock.ConfigMock {
542 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