(t *testing.T)
| 35 | } |
| 36 | |
| 37 | func 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 | ) |
nothing calls this directly
no test coverage detected