MCPcopy Index your code
hub / github.com/cli/cli / TestResolveRef

Function TestResolveRef

internal/skills/discovery/discovery_test.go:420–720  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

418}
419
420func TestResolveRef(t *testing.T) {
421 tests := []struct {
422 name string
423 version string
424 stubs func(*httpmock.Registry)
425 wantRef string
426 wantSHA string
427 wantErr string
428 }{
429 {
430 name: "short name resolves as branch first",
431 version: "main",
432 stubs: func(reg *httpmock.Registry) {
433 reg.Register(
434 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/ref/heads/main"),
435 httpmock.JSONResponse(map[string]interface{}{
436 "object": map[string]interface{}{"sha": "branch-sha"},
437 }))
438 },
439 wantRef: "refs/heads/main",
440 wantSHA: "branch-sha",
441 },
442 {
443 name: "short name falls back to tag when branch not found",
444 version: "v1.0",
445 stubs: func(reg *httpmock.Registry) {
446 reg.Register(
447 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/ref/heads/v1.0"),
448 httpmock.StatusStringResponse(404, "not found"))
449 reg.Register(
450 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/ref/tags/v1.0"),
451 httpmock.JSONResponse(map[string]interface{}{
452 "object": map[string]interface{}{"sha": "abc123", "type": "commit"},
453 }))
454 },
455 wantRef: "refs/tags/v1.0",
456 wantSHA: "abc123",
457 },
458 {
459 name: "short name resolves annotated tag",
460 version: "v2.0",
461 stubs: func(reg *httpmock.Registry) {
462 reg.Register(
463 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/ref/heads/v2.0"),
464 httpmock.StatusStringResponse(404, "not found"))
465 reg.Register(
466 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/ref/tags/v2.0"),
467 httpmock.JSONResponse(map[string]interface{}{
468 "object": map[string]interface{}{"sha": "tag-obj-sha", "type": "tag"},
469 }))
470 reg.Register(
471 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/tags/tag-obj-sha"),
472 httpmock.JSONResponse(map[string]interface{}{
473 "object": map[string]interface{}{"sha": "real-commit-sha"},
474 }))
475 },
476 wantRef: "refs/tags/v2.0",
477 wantSHA: "real-commit-sha",

Callers

nothing calls this directly

Calls 11

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
JSONResponseFunction · 0.92
StatusStringResponseFunction · 0.92
NewClientFromHTTPFunction · 0.92
ResolveRefFunction · 0.85
ContainsMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected