MCPcopy
hub / github.com/cli/cli / TestApiLogFetcher

Function TestApiLogFetcher

pkg/cmd/run/view/logs_test.go:37–133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestApiLogFetcher(t *testing.T) {
38 tests := []struct {
39 name string
40 httpStubs func(reg *httpmock.Registry)
41 wantErr string
42 wantContent string
43 }{
44 {
45 // This is the real flow as of now. When we call the `/logs`
46 // endpoint, the server will respond with a 302 redirect, pointing
47 // to the actual log file URL.
48 name: "successful with redirect (HTTP 302, then HTTP 200)",
49 httpStubs: func(reg *httpmock.Registry) {
50 reg.Register(
51 httpmock.REST("GET", "repos/OWNER/REPO/actions/jobs/123/logs"),
52 httpmock.WithHeader(
53 httpmock.StatusStringResponse(http.StatusFound, ""),
54 "Location",
55 "https://some.domain/the-actual-log",
56 ),
57 )
58 reg.Register(
59 httpmock.REST("GET", "the-actual-log"),
60 httpmock.StringResponse("blah blah"),
61 )
62 },
63 wantContent: "blah blah",
64 },
65 {
66 name: "successful without redirect (HTTP 200)",
67 httpStubs: func(reg *httpmock.Registry) {
68 reg.Register(
69 httpmock.REST("GET", "repos/OWNER/REPO/actions/jobs/123/logs"),
70 httpmock.StatusStringResponse(http.StatusOK, "blah blah"),
71 )
72 },
73 wantContent: "blah blah",
74 },
75 {
76 name: "failed with not found error (HTTP 404)",
77 httpStubs: func(reg *httpmock.Registry) {
78 reg.Register(
79 httpmock.REST("GET", "repos/OWNER/REPO/actions/jobs/123/logs"),
80 httpmock.StatusStringResponse(http.StatusNotFound, ""),
81 )
82 },
83 wantErr: "log not found: 123",
84 },
85 {
86 name: "failed with server error (HTTP 500)",
87 httpStubs: func(reg *httpmock.Registry) {
88 reg.Register(
89 httpmock.REST("GET", "repos/OWNER/REPO/actions/jobs/123/logs"),
90 httpmock.JSONErrorResponse(http.StatusInternalServerError, ghAPI.HTTPError{
91 Message: "blah blah",
92 StatusCode: http.StatusInternalServerError,
93 }),
94 )

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
VerifyMethod · 0.95
GetLogMethod · 0.95
RESTFunction · 0.92
WithHeaderFunction · 0.92
StatusStringResponseFunction · 0.92
StringResponseFunction · 0.92
JSONErrorResponseFunction · 0.92
NewFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected