MCPcopy
hub / github.com/cli/cli / TestParseDiscussionOrCommentArg

Function TestParseDiscussionOrCommentArg

pkg/cmd/discussion/shared/lookup_test.go:126–283  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestParseDiscussionOrCommentArg(t *testing.T) {
127 tests := []struct {
128 name string
129 arg string
130 wantNumber int32
131 wantOwner string
132 wantRepo string
133 wantHost string
134 wantCommentNodeID string
135 wantCommentDBID int64
136 wantErr string
137 }{
138 // Same cases as ParseDiscussionArg
139 {
140 name: "empty",
141 arg: "",
142 wantErr: `invalid argument: "" (expected a discussion number, URL, or comment ID)`,
143 },
144 {
145 name: "whitespaces",
146 arg: " ",
147 wantErr: `invalid argument: " " (expected a discussion number, URL, or comment ID)`,
148 },
149 {
150 name: "invalid string",
151 arg: "not-a-number",
152 wantErr: `invalid argument: "not-a-number" (expected a discussion number, URL, or comment ID)`,
153 },
154 {
155 name: "hash only",
156 arg: "#",
157 wantErr: `invalid argument: "#" (expected a discussion number, URL, or comment ID)`,
158 },
159 {
160 name: "hash non-numeric",
161 arg: "#abc",
162 wantErr: `invalid argument: "#abc" (expected a discussion number, URL, or comment ID)`,
163 },
164 {
165 name: "URL with wrong path",
166 arg: "https://github.com/owner/repo/issues/10",
167 wantErr: `invalid discussion URL: "https://github.com/owner/repo/issues/10"`,
168 },
169 {
170 name: "URL missing number",
171 arg: "https://github.com/owner/repo/discussions/",
172 wantErr: `invalid discussion URL: "https://github.com/owner/repo/discussions/"`,
173 },
174 {
175 name: "URL with overflowing number",
176 arg: "https://github.com/owner/repo/discussions/99999999999999999999",
177 wantErr: `invalid discussion number in URL: "99999999999999999999"`,
178 },
179 {
180 name: "comment URL with invalid fragment",
181 arg: "https://github.com/owner/repo/discussions/5#discussioncomment-abc",
182 wantErr: `invalid comment ID in URL fragment: "discussioncomment-abc"`,
183 },

Callers

nothing calls this directly

Calls 7

EqualMethod · 0.80
RunMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected