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

Function TestParseIssueArg

pkg/cmd/issue/artifact/shared/shared_test.go:52–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestParseIssueArg(t *testing.T) {
53 tests := []struct {
54 name string
55 arg string
56 wantNumber int
57 wantRepo string
58 wantBaseRepoCalls int
59 wantErr string
60 }{
61 {
62 name: "a number uses the base repository",
63 arg: "142",
64 wantNumber: 142,
65 wantRepo: "github.com/OWNER/REPO",
66 wantBaseRepoCalls: 1,
67 },
68 {
69 name: "a number with a hash",
70 arg: "#142",
71 wantNumber: 142,
72 wantRepo: "github.com/OWNER/REPO",
73 wantBaseRepoCalls: 1,
74 },
75 {
76 name: "an issue URL names its repository",
77 arg: "https://github.com/monalisa/monas-cafe/issues/142",
78 wantNumber: 142,
79 wantRepo: "github.com/monalisa/monas-cafe",
80 },
81 {
82 name: "an issue URL on a ghe.com host",
83 arg: "https://monas-cafe.ghe.com/monalisa/monas-cafe/issues/142",
84 wantNumber: 142,
85 wantRepo: "monas-cafe.ghe.com/monalisa/monas-cafe",
86 },
87 {
88 name: "a pull request URL parses, so the lookup can refuse it",
89 arg: "https://github.com/monalisa/monas-cafe/pull/158",
90 wantNumber: 158,
91 wantRepo: "github.com/monalisa/monas-cafe",
92 },
93 {
94 name: "neither a number nor a URL",
95 arg: "OAuth",
96 wantErr: `invalid issue format: "OAuth"`,
97 },
98 }
99
100 for _, tt := range tests {
101 t.Run(tt.name, func(t *testing.T) {
102 baseRepoCalls := 0
103 baseRepo := func() (ghrepo.Interface, error) {
104 baseRepoCalls++
105 return ghrepo.New("OWNER", "REPO"), nil
106 }
107
108 number, repoFunc, err := ParseIssueArg(tt.arg, baseRepo)
109

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
FullNameFunction · 0.92
ParseIssueArgFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected