MCPcopy Index your code
hub / github.com/cli/cli / TestClientAuthenticatedCommand

Function TestClientAuthenticatedCommand

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

Source from the content-addressed store, hash-verified

63}
64
65func TestClientAuthenticatedCommand(t *testing.T) {
66 tests := []struct {
67 name string
68 path string
69 pattern CredentialPattern
70 wantArgs []string
71 wantErr error
72 }{
73 {
74 name: "when credential pattern allows for anything, credential helper matches everything",
75 path: "path/to/gh",
76 pattern: AllMatchingCredentialsPattern,
77 wantArgs: []string{"path/to/git", "-c", "credential.helper=", "-c", `credential.helper=!"path/to/gh" auth git-credential`, "fetch"},
78 },
79 {
80 name: "when credential pattern is set, credential helper only matches that pattern",
81 path: "path/to/gh",
82 pattern: CredentialPattern{pattern: "https://github.com"},
83 wantArgs: []string{"path/to/git", "-c", "credential.https://github.com.helper=", "-c", `credential.https://github.com.helper=!"path/to/gh" auth git-credential`, "fetch"},
84 },
85 {
86 name: "fallback when GhPath is not set",
87 pattern: AllMatchingCredentialsPattern,
88 wantArgs: []string{"path/to/git", "-c", "credential.helper=", "-c", `credential.helper=!"gh" auth git-credential`, "fetch"},
89 },
90 {
91 name: "errors when attempting to use an empty pattern that isn't marked all matching",
92 pattern: CredentialPattern{allMatching: false, pattern: ""},
93 wantErr: fmt.Errorf("empty credential pattern is not allowed unless provided explicitly"),
94 },
95 }
96 for _, tt := range tests {
97 t.Run(tt.name, func(t *testing.T) {
98 client := Client{
99 GhPath: tt.path,
100 GitPath: "path/to/git",
101 }
102 cmd, err := client.AuthenticatedCommand(context.Background(), tt.pattern, "fetch")
103 if tt.wantErr != nil {
104 require.Equal(t, tt.wantErr, err)
105 return
106 }
107 require.Equal(t, tt.wantArgs, cmd.Args)
108 })
109 }
110}
111
112func TestClientRemotes(t *testing.T) {
113 tempDir := t.TempDir()

Callers

nothing calls this directly

Calls 4

AuthenticatedCommandMethod · 0.95
EqualMethod · 0.80
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected