History

test: cover local pull API helpers

Peter Steinberger committed 5 months ago

Commit 869d2e41 parent 76cc41a1 file · +45 −0Browse files

Unified · Split

internal/cli/gh_shim_detail_test.go+45−0
@@ -216,6 +216,51 @@ func TestParseLocalGHAPIArgsDeclinesBehaviorChangingFlags(t *testing.T) { · 215 unmodified lines
216 }216 }
217}217}
218 218
219func TestParseLocalGHAPIArgsAcceptedForms(t *testing.T) {
220 route, jqExpr, ok := parseLocalGHAPIArgs([]string{"api", "--method", "GET", "--cache", "1h", "repos/openclaw/openclaw/pulls/12", "--jq=.number"})
221 if !ok || route != "repos/openclaw/openclaw/pulls/12" || jqExpr != ".number" {
222 t.Fatalf("parseLocalGHAPIArgs long flags = %q %q %v", route, jqExpr, ok)
223 }
224 route, jqExpr, ok = parseLocalGHAPIArgs([]string{"api", "--method=GET", "--cache=1h", "repos/openclaw/openclaw/pulls/12?foo=bar", "-q", ".title"})
225 if !ok || route != "repos/openclaw/openclaw/pulls/12?foo=bar" || jqExpr != ".title" {
226 t.Fatalf("parseLocalGHAPIArgs equals flags = %q %q %v", route, jqExpr, ok)
227 }
228 if _, _, ok := parseLocalGHAPIArgs([]string{"api", "--method", "POST", "repos/openclaw/openclaw/pulls/12"}); ok {
229 t.Fatal("POST should not be locally handled")
230 }
231}
232
233func TestParsePullAPIRouteAndRESTPullID(t *testing.T) {
234 owner, repo, number, ok := parsePullAPIRoute("/repos/openclaw/gitcrawl/pulls/42?ignored=true")
235 if !ok || owner != "openclaw" || repo != "gitcrawl" || number != 42 {
236 t.Fatalf("parsePullAPIRoute = %q %q %d %v", owner, repo, number, ok)
237 }
238 for _, route := range []string{"repos/openclaw/gitcrawl/issues/42", "repos/openclaw/gitcrawl/pulls/nope", "repos/openclaw//pulls/42"} {
239 if _, _, _, ok := parsePullAPIRoute(route); ok {
240 t.Fatalf("parsePullAPIRoute(%q) ok, want false", route)
241 }
242 }
243 for _, tc := range []struct {
244 raw any
245 fallback string
246 want any
247 ok bool
248 }{
249 {float64(12), "", float64(12), true},
250 {int(13), "", int(13), true},
251 {int64(14), "", int64(14), true},
252 {"15", "", int64(15), true},
253 {"node-id", "", "node-id", true},
254 {nil, "16", int64(16), true},
255 {nil, "", nil, false},
256 } {
257 got, ok := restPullID(tc.raw, tc.fallback)
258 if ok != tc.ok || got != tc.want {
259 t.Fatalf("restPullID(%#v,%q) = %#v %v, want %#v %v", tc.raw, tc.fallback, got, ok, tc.want, tc.ok)
260 }
261 }
262}
263
219func TestGHPRMergedFieldsUseRawPullDetail(t *testing.T) {264func TestGHPRMergedFieldsUseRawPullDetail(t *testing.T) {
220 cache := store.PullRequestCache{265 cache := store.PullRequestCache{
221 Detail: store.PullRequestDetail{RawJSON: `{"merged":true,"merged_at":"2026-04-27T03:00:00Z","merge_commit_sha":"final123","auto_merge":{"enabled_by":{"login":"alice"},"merge_method":"SQUASH","commit_title":"ship it","commit_message":"details"}}`},266 Detail: store.PullRequestDetail{RawJSON: `{"merged":true,"merged_at":"2026-04-27T03:00:00Z","merge_commit_sha":"final123","auto_merge":{"enabled_by":{"login":"alice"},"merge_method":"SQUASH","commit_title":"ship it","commit_message":"details"}}`},

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t