MCPcopy
hub / github.com/cli/cli / TestFetchRefSHA

Function TestFetchRefSHA

pkg/cmd/release/shared/fetch_test.go:16–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestFetchRefSHA(t *testing.T) {
17 tests := []struct {
18 name string
19 tagName string
20 responseStatus int
21 responseBody string
22 responseMessage string
23 expectedSHA string
24 errorMessage string
25 }{
26 {
27 name: "match (200)",
28 tagName: "v1.2.3",
29 responseStatus: 200,
30 responseBody: `{"object": {"sha": "1234567890abcdef1234567890abcdef12345678"}}`,
31 expectedSHA: "1234567890abcdef1234567890abcdef12345678",
32 },
33 {
34 name: "non-match (404)",
35 tagName: "v1.2.3",
36 responseStatus: 404,
37 responseMessage: `Not found`,
38 errorMessage: "release not found",
39 },
40 {
41 name: "server error (500)",
42 tagName: "v1.2.3",
43 responseStatus: 500,
44 responseMessage: `arbitrary error"`,
45 errorMessage: "HTTP 500: arbitrary error\" (https://api.github.com/repos/owner/repo/git/ref/tags/v1.2.3)",
46 },
47 {
48 name: "malformed JSON with 200",
49 tagName: "v1.2.3",
50 responseStatus: 200,
51 responseBody: `{"object": {"sha":`,
52 errorMessage: "failed to parse ref response: unexpected EOF",
53 },
54 }
55
56 for _, tt := range tests {
57 t.Run(tt.name, func(t *testing.T) {
58 fakeHTTP := &httpmock.Registry{}
59 defer fakeHTTP.Verify(t)
60
61 repo, err := ghrepo.FromFullName("owner/repo")
62 require.NoError(t, err)
63
64 path := "repos/owner/repo/git/ref/tags/" + tt.tagName
65 if tt.responseStatus == 404 || tt.responseStatus == 500 {
66 fakeHTTP.Register(
67 httpmock.REST("GET", path),
68 httpmock.JSONErrorResponse(tt.responseStatus, api.HTTPError{
69 StatusCode: tt.responseStatus,
70 Message: tt.responseMessage,
71 }),
72 )
73 } else {

Callers

nothing calls this directly

Calls 11

VerifyMethod · 0.95
RegisterMethod · 0.95
FromFullNameFunction · 0.92
RESTFunction · 0.92
JSONErrorResponseFunction · 0.92
StatusStringResponseFunction · 0.92
FetchRefSHAFunction · 0.85
ContainsMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected