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

Function TestParseRepoArgs

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

Source from the content-addressed store, hash-verified

19)
20
21func TestParseRepoArgs(t *testing.T) {
22 tests := []struct {
23 name string
24 args []string
25 want repoOptions
26 err string
27 }{
28 {name: "defaults", args: []string{"octo/hello"}, want: repoOptions{name: "octo/hello", branch: "main"}},
29 {name: "synthetic namespace", args: []string{"example.invalid/hello"}, want: repoOptions{name: "example.invalid/hello", branch: "main"}},
30 {name: "host and branch", args: []string{"example.com/octo/hello.git", "--branch", "topic/one"}, want: repoOptions{name: "example.com/octo/hello.git", branch: "topic/one"}},
31 {name: "missing name", err: `invalid repository ""; use [HOST/]OWNER/REPO`},
32 {name: "path traversal", args: []string{"octo/.."}, err: `invalid repository "octo/.."; use [HOST/]OWNER/REPO`},
33 {name: "absolute path", args: []string{"/octo/hello"}, err: `invalid repository "/octo/hello"; use [HOST/]OWNER/REPO`},
34 {name: "URL is not a name", args: []string{"https://github.com/octo/hello"}, err: `invalid repository "https://github.com/octo/hello"; use [HOST/]OWNER/REPO`},
35 {name: "empty branch", args: []string{"octo/hello", "--branch", ""}, err: "--branch cannot be empty"},
36 }
37 for _, tt := range tests {
38 t.Run(tt.name, func(t *testing.T) {
39 got, err := parseRepoArgs(tt.args)
40 if tt.err != "" {
41 require.EqualError(t, err, tt.err)
42 return
43 }
44 require.NoError(t, err)
45 assert.Equal(t, tt.want, got)
46 })
47 }
48}
49
50func TestCmdRepo(t *testing.T) {
51 tests := []struct {

Callers

nothing calls this directly

Calls 3

parseRepoArgsFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected