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

Function TestParseGitArgs

script/ghmock/gitcmd_test.go:168–200  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

166}
167
168func TestParseGitArgs(t *testing.T) {
169 tests := []struct {
170 name string
171 args []string
172 want gitOptions
173 err string
174 }{
175 {name: "setup", args: []string{"--", "init", "main"}, want: gitOptions{build: 1, timeout: time.Minute, args: []string{"init", "main"}}},
176 {name: "inspect result", args: []string{"--run", "latest", "--build", "2", "--in", "feature", "--", "status"}, want: gitOptions{run: "latest", build: 2, in: "feature", timeout: time.Minute, args: []string{"status"}}},
177 {name: "inspect baseline", args: []string{"--run", "id", "--before", "--", "status"}, want: gitOptions{run: "id", before: true, build: 1, timeout: time.Minute, args: []string{"status"}}},
178 {name: "stdin", args: []string{"--stdin", "x", "--", "hash-object", "--stdin"}, want: gitOptions{build: 1, stdin: "x", timeout: time.Minute, args: []string{"hash-object", "--stdin"}}},
179 {name: "missing command", err: "missing git arguments; put them after --"},
180 {name: "nonpositive build", args: []string{"--build", "0", "--", "status"}, err: "--build must be positive"},
181 {name: "build without run", args: []string{"--build", "2", "--", "status"}, err: "--build requires --run"},
182 {name: "before without run", args: []string{"--before", "--", "status"}, err: "--before requires --run"},
183 {name: "explicit default build without run", args: []string{"--build", "1", "--", "status"}, err: "--build requires --run"},
184 {name: "empty run", args: []string{"--run", "", "--", "status"}, err: "--run cannot be empty"},
185 {name: "before and build", args: []string{"--run", "latest", "--before", "--build", "1", "--", "status"}, err: "--before and --build cannot be used together"},
186 {name: "outside workspace", args: []string{"--in", "../other", "--", "status"}, err: "--in must be a relative path inside the Git workspace"},
187 {name: "nonpositive timeout", args: []string{"--timeout", "0s", "--", "status"}, err: "--timeout must be positive"},
188 }
189 for _, tt := range tests {
190 t.Run(tt.name, func(t *testing.T) {
191 got, err := parseGitArgs(tt.args)
192 if tt.err != "" {
193 require.EqualError(t, err, tt.err)
194 return
195 }
196 require.NoError(t, err)
197 assert.Equal(t, tt.want, got)
198 })
199 }
200}
201
202func TestCmdGit(t *testing.T) {
203 tests := []struct {

Callers

nothing calls this directly

Calls 3

parseGitArgsFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected