feat(users): add quota attachment endpoints
All checks were successful
Security Scan / security (push) Successful in 11s
Test / test (push) Successful in 1m41s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 02:28:59 +00:00
parent 7a591810ad
commit 42286a1ee3
2 changed files with 70 additions and 0 deletions

View file

@ -72,6 +72,16 @@ func (s *UserService) IterQuotaArtifacts(ctx context.Context) iter.Seq2[types.Qu
return ListIter[types.QuotaUsedArtifact](ctx, s.client, "/api/v1/user/quota/artifacts", nil)
}
// ListQuotaAttachments returns all attachments affecting the authenticated user's quota.
func (s *UserService) ListQuotaAttachments(ctx context.Context) ([]types.QuotaUsedAttachment, error) {
return ListAll[types.QuotaUsedAttachment](ctx, s.client, "/api/v1/user/quota/attachments", nil)
}
// IterQuotaAttachments returns an iterator over all attachments affecting the authenticated user's quota.
func (s *UserService) IterQuotaAttachments(ctx context.Context) iter.Seq2[types.QuotaUsedAttachment, error] {
return ListIter[types.QuotaUsedAttachment](ctx, s.client, "/api/v1/user/quota/attachments", nil)
}
// ListEmails returns all email addresses for the authenticated user.
func (s *UserService) ListEmails(ctx context.Context) ([]types.Email, error) {
return ListAll[types.Email](ctx, s.client, "/api/v1/user/emails", nil)

View file

@ -223,6 +223,66 @@ func TestUserService_IterQuotaArtifacts_Good(t *testing.T) {
}
}
func TestUserService_ListQuotaAttachments_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("expected GET, got %s", r.Method)
}
if r.URL.Path != "/api/v1/user/quota/attachments" {
t.Errorf("wrong path: %s", r.URL.Path)
}
w.Header().Set("X-Total-Count", "2")
json.NewEncoder(w).Encode([]types.QuotaUsedAttachment{
{Name: "issue-attachment.png", Size: 123, APIURL: "https://example.com/api/attachments/1"},
{Name: "release-attachment.tar.gz", Size: 456, APIURL: "https://example.com/api/attachments/2"},
})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
attachments, err := f.Users.ListQuotaAttachments(context.Background())
if err != nil {
t.Fatal(err)
}
if len(attachments) != 2 {
t.Fatalf("got %d attachments, want 2", len(attachments))
}
if attachments[0].Name != "issue-attachment.png" || attachments[0].Size != 123 {
t.Errorf("unexpected first attachment: %+v", attachments[0])
}
}
func TestUserService_IterQuotaAttachments_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("expected GET, got %s", r.Method)
}
if r.URL.Path != "/api/v1/user/quota/attachments" {
t.Errorf("wrong path: %s", r.URL.Path)
}
w.Header().Set("X-Total-Count", "1")
json.NewEncoder(w).Encode([]types.QuotaUsedAttachment{
{Name: "issue-attachment.png", Size: 123, APIURL: "https://example.com/api/attachments/1"},
})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
var got []types.QuotaUsedAttachment
for attachment, err := range f.Users.IterQuotaAttachments(context.Background()) {
if err != nil {
t.Fatal(err)
}
got = append(got, attachment)
}
if len(got) != 1 {
t.Fatalf("got %d attachments, want 1", len(got))
}
if got[0].Name != "issue-attachment.png" {
t.Errorf("unexpected attachment: %+v", got[0])
}
}
func TestUserService_ListEmails_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {