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