MCPcopy
hub / github.com/cli/cli / TestNewGitClient

Function TestNewGitClient

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

Source from the content-addressed store, hash-verified

401}
402
403func TestNewGitClient(t *testing.T) {
404 tests := []struct {
405 name string
406 config gh.Config
407 executable string
408 wantAuthHosts []string
409 wantGhPath string
410 }{
411 {
412 name: "creates git client",
413 config: defaultConfig(),
414 executable: filepath.Join("path", "to", "gh"),
415 wantAuthHosts: []string{"nonsense.com"},
416 wantGhPath: filepath.Join("path", "to", "gh"),
417 },
418 }
419 for _, tt := range tests {
420 t.Run(tt.name, func(t *testing.T) {
421 f := &cmdutil.Factory{}
422 f.Config = func() (gh.Config, error) {
423 if tt.config == nil {
424 return config.NewBlankConfig(), nil
425 } else {
426 return tt.config, nil
427 }
428 }
429 f.ExecutablePath = tt.executable
430 ios, _, _, _ := iostreams.Test()
431 f.IOStreams = ios
432 c := newGitClient(f)
433 assert.Equal(t, tt.wantGhPath, c.GhPath)
434 assert.Equal(t, ios.In, c.Stdin)
435 assert.Equal(t, ios.Out, c.Stdout)
436 assert.Equal(t, ios.ErrOut, c.Stderr)
437 })
438 }
439}
440
441func defaultConfig() *ghmock.ConfigMock {
442 cfg := config.NewFromString("")

Callers

nothing calls this directly

Calls 7

NewBlankConfigFunction · 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