(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func TestUpload(t *testing.T) { |
| 60 | a := testAsset(t, "shot.png", "image/png", "the bytes") |
| 61 | |
| 62 | var gotBody []byte |
| 63 | reg := &httpmock.Registry{} |
| 64 | defer reg.Verify(t) |
| 65 | reg.Register( |
| 66 | httpmock.REST("POST", "user-attachments/assets"), |
| 67 | func(req *http.Request) (*http.Response, error) { |
| 68 | var err error |
| 69 | gotBody, err = io.ReadAll(req.Body) |
| 70 | require.NoError(t, err) |
| 71 | return httpmock.StatusStringResponse(201, `{"url":"https://github.com/user-attachments/assets/be9b3920"}`)(req) |
| 72 | }, |
| 73 | ) |
| 74 | |
| 75 | assetURL, err := newTestUploader(t, reg, "github.com", 1234).upload(context.Background(), a) |
| 76 | |
| 77 | require.NoError(t, err) |
| 78 | assert.Equal(t, "https://github.com/user-attachments/assets/be9b3920", assetURL) |
| 79 | assert.Equal(t, "the bytes", string(gotBody)) |
| 80 | |
| 81 | require.Len(t, reg.Requests, 1) |
| 82 | req := reg.Requests[0] |
| 83 | assert.Equal(t, "POST", req.Method) |
| 84 | assert.Equal(t, "https://uploads.github.com/user-attachments/assets?content_type=image%2Fpng&name=shot.png&repository_id=1234", req.URL.String()) |
| 85 | assert.Equal(t, "application/octet-stream", req.Header.Get("Content-Type")) |
| 86 | assert.Equal(t, "application/vnd.github+json", req.Header.Get("Accept")) |
| 87 | assert.Equal(t, int64(9), req.ContentLength) |
| 88 | } |
| 89 | |
| 90 | func TestUploadHostForTenant(t *testing.T) { |
| 91 | a := testAsset(t, "shot.png", "image/png", "x") |
nothing calls this directly
no test coverage detected