(t *testing.T)
| 418 | } |
| 419 | |
| 420 | func 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", |
nothing calls this directly
no test coverage detected