Skip to content

Commit

Permalink
fix: GetQuotaStatus method (#141)
Browse files Browse the repository at this point in the history
* GetQuotaStatus method is wrongly typed. Changed to master aim

* add tests for quotas

* Reformat whitespaces

---------

Co-authored-by: Serkan AKÇIN <serkan.akcin@atilim.edu.tr>
  • Loading branch information
christian-wiese and Serkan AKÇIN authored Apr 11, 2024
1 parent 01d290a commit f9dd891
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nexus3/pkg/blobstore/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *BlobStoreAzureService) Delete(name string) error {
return deleteBlobstore(s.Client, name)
}

func (s *BlobStoreAzureService) GetQuotaStatus(name string) error {
func (s *BlobStoreAzureService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
return getBlobstoreQuotaStatus(s.Client, name)
}

Expand Down
2 changes: 1 addition & 1 deletion nexus3/pkg/blobstore/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ func (s *BlobStoreFileService) Delete(name string) error {
return deleteBlobstore(s.Client, name)
}

func (s *BlobStoreFileService) GetQuotaStatus(name string) error {
func (s *BlobStoreFileService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
return getBlobstoreQuotaStatus(s.Client, name)
}
4 changes: 4 additions & 0 deletions nexus3/pkg/blobstore/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func TestBlobstoreFile(t *testing.T) {
assert.NotNil(t, updatedBlobstore)
assert.NotNil(t, updatedBlobstore.SoftQuota)

quotaStatus, err := getBlobstoreQuotaStatus(service.Client, updatedBlobstore.Name)
assert.Nil(t, err)
assert.Equal(t, updatedBlobstore.Name, quotaStatus.BlobStoreName)

err = service.File.Delete(bs.Name)
assert.Nil(t, err)

Expand Down
2 changes: 1 addition & 1 deletion nexus3/pkg/blobstore/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ func (s *BlobStoreGroupService) Delete(name string) error {
return deleteBlobstore(s.Client, name)
}

func (s *BlobStoreGroupService) GetQuotaStatus(name string) error {
func (s *BlobStoreGroupService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
return getBlobstoreQuotaStatus(s.Client, name)
}
4 changes: 4 additions & 0 deletions nexus3/pkg/blobstore/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func TestBlobstoreGroup(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, updatedGroup)

quotaStatus, err := getBlobstoreQuotaStatus(service.Client, updatedGroup.Name)
assert.Nil(t, err)
assert.Equal(t, updatedGroup.Name, quotaStatus.BlobStoreName)

assert.NotNil(t, updatedGroup.SoftQuota)
assert.Equal(t, blobstore.GroupFillPolicyWriteToFirst, updatedGroup.FillPolicy)

Expand Down
2 changes: 1 addition & 1 deletion nexus3/pkg/blobstore/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ func (s *BlobStoreS3Service) Delete(name string) error {
return deleteBlobstore(s.Client, name)
}

func (s *BlobStoreS3Service) GetQuotaStatus(name string) error {
func (s *BlobStoreS3Service) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
return getBlobstoreQuotaStatus(s.Client, name)
}
17 changes: 17 additions & 0 deletions nexus3/pkg/blobstore/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ func TestBlobstoreS3(t *testing.T) {
assert.NotNil(t, s3BS.BucketConfiguration.Bucket)
assert.NotNil(t, s3BS.BucketConfiguration.BucketSecurity)

s3BS.SoftQuota = &blobstore.SoftQuota{
Type: "spaceRemainingQuota",
Limit: 100000000,
}

err = service.S3.Update(s3BS.Name, s3BS)
assert.Nil(t, err)

updatedBlobstore, err := service.S3.Get(s3BS.Name)
assert.Nil(t, err)
assert.NotNil(t, updatedBlobstore)
assert.NotNil(t, updatedBlobstore.SoftQuota)

quotaStatus, err := getBlobstoreQuotaStatus(service.Client, updatedBlobstore.Name)
assert.Nil(t, err)
assert.Equal(t, updatedBlobstore.Name, quotaStatus.BlobStoreName)

err = service.S3.Delete(bs.Name)
assert.Nil(t, err)
}
20 changes: 13 additions & 7 deletions nexus3/pkg/blobstore/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,24 @@ func deleteBlobstore(c *client.Client, name string) error {
return nil
}

func (s *BlobStoreService) GetQuotaStatus(name string) error {
func (s *BlobStoreService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
return getBlobstoreQuotaStatus(s.Client, name)
}

func getBlobstoreQuotaStatus(c *client.Client, name string) error {
body, resp, err := c.Delete(fmt.Sprintf("%s/%s", blobstoreAPIEndpoint, name))
func getBlobstoreQuotaStatus(c *client.Client, name string) (*blobstore.QuotaStatus, error) {
body, resp, err := c.Get(fmt.Sprintf("%s/%s/%s", blobstoreAPIEndpoint, name, "quota-status"), nil)
if err != nil {
return err
return nil, err
}

if resp.StatusCode != http.StatusNoContent {
return fmt.Errorf("could not delete blobstore \"%s\": HTTP: %d, %s", name, resp.StatusCode, string(body))
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("could not get quotastatus for blobstore %s", name)
}
return nil

var quotaStatus blobstore.QuotaStatus
if err := json.Unmarshal(body, &quotaStatus); err != nil {
return nil, fmt.Errorf("could not unmarshal of blobstore quotastatus: %v", err)
}

return &quotaStatus, nil
}

0 comments on commit f9dd891

Please sign in to comment.