Skip to content

Commit f9dd891

Browse files
christian-wieseSerkan AKÇIN
and
Serkan AKÇIN
authored
fix: GetQuotaStatus method (#141)
* GetQuotaStatus method is wrongly typed. Changed to master aim * add tests for quotas * Reformat whitespaces --------- Co-authored-by: Serkan AKÇIN <[email protected]>
1 parent 01d290a commit f9dd891

File tree

8 files changed

+42
-11
lines changed

8 files changed

+42
-11
lines changed

nexus3/pkg/blobstore/azure.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (s *BlobStoreAzureService) Delete(name string) error {
7878
return deleteBlobstore(s.Client, name)
7979
}
8080

81-
func (s *BlobStoreAzureService) GetQuotaStatus(name string) error {
81+
func (s *BlobStoreAzureService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
8282
return getBlobstoreQuotaStatus(s.Client, name)
8383
}
8484

nexus3/pkg/blobstore/file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ func (s *BlobStoreFileService) Delete(name string) error {
7878
return deleteBlobstore(s.Client, name)
7979
}
8080

81-
func (s *BlobStoreFileService) GetQuotaStatus(name string) error {
81+
func (s *BlobStoreFileService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
8282
return getBlobstoreQuotaStatus(s.Client, name)
8383
}

nexus3/pkg/blobstore/file_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func TestBlobstoreFile(t *testing.T) {
4141
assert.NotNil(t, updatedBlobstore)
4242
assert.NotNil(t, updatedBlobstore.SoftQuota)
4343

44+
quotaStatus, err := getBlobstoreQuotaStatus(service.Client, updatedBlobstore.Name)
45+
assert.Nil(t, err)
46+
assert.Equal(t, updatedBlobstore.Name, quotaStatus.BlobStoreName)
47+
4448
err = service.File.Delete(bs.Name)
4549
assert.Nil(t, err)
4650

nexus3/pkg/blobstore/group.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ func (s *BlobStoreGroupService) Delete(name string) error {
7878
return deleteBlobstore(s.Client, name)
7979
}
8080

81-
func (s *BlobStoreGroupService) GetQuotaStatus(name string) error {
81+
func (s *BlobStoreGroupService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
8282
return getBlobstoreQuotaStatus(s.Client, name)
8383
}

nexus3/pkg/blobstore/group_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func TestBlobstoreGroup(t *testing.T) {
5555
assert.Nil(t, err)
5656
assert.NotNil(t, updatedGroup)
5757

58+
quotaStatus, err := getBlobstoreQuotaStatus(service.Client, updatedGroup.Name)
59+
assert.Nil(t, err)
60+
assert.Equal(t, updatedGroup.Name, quotaStatus.BlobStoreName)
61+
5862
assert.NotNil(t, updatedGroup.SoftQuota)
5963
assert.Equal(t, blobstore.GroupFillPolicyWriteToFirst, updatedGroup.FillPolicy)
6064

nexus3/pkg/blobstore/s3.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ func (s *BlobStoreS3Service) Delete(name string) error {
7777
return deleteBlobstore(s.Client, name)
7878
}
7979

80-
func (s *BlobStoreS3Service) GetQuotaStatus(name string) error {
80+
func (s *BlobStoreS3Service) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
8181
return getBlobstoreQuotaStatus(s.Client, name)
8282
}

nexus3/pkg/blobstore/s3_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ func TestBlobstoreS3(t *testing.T) {
5050
assert.NotNil(t, s3BS.BucketConfiguration.Bucket)
5151
assert.NotNil(t, s3BS.BucketConfiguration.BucketSecurity)
5252

53+
s3BS.SoftQuota = &blobstore.SoftQuota{
54+
Type: "spaceRemainingQuota",
55+
Limit: 100000000,
56+
}
57+
58+
err = service.S3.Update(s3BS.Name, s3BS)
59+
assert.Nil(t, err)
60+
61+
updatedBlobstore, err := service.S3.Get(s3BS.Name)
62+
assert.Nil(t, err)
63+
assert.NotNil(t, updatedBlobstore)
64+
assert.NotNil(t, updatedBlobstore.SoftQuota)
65+
66+
quotaStatus, err := getBlobstoreQuotaStatus(service.Client, updatedBlobstore.Name)
67+
assert.Nil(t, err)
68+
assert.Equal(t, updatedBlobstore.Name, quotaStatus.BlobStoreName)
69+
5370
err = service.S3.Delete(bs.Name)
5471
assert.Nil(t, err)
5572
}

nexus3/pkg/blobstore/service.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,24 @@ func deleteBlobstore(c *client.Client, name string) error {
7171
return nil
7272
}
7373

74-
func (s *BlobStoreService) GetQuotaStatus(name string) error {
74+
func (s *BlobStoreService) GetQuotaStatus(name string) (*blobstore.QuotaStatus, error) {
7575
return getBlobstoreQuotaStatus(s.Client, name)
7676
}
7777

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

84-
if resp.StatusCode != http.StatusNoContent {
85-
return fmt.Errorf("could not delete blobstore \"%s\": HTTP: %d, %s", name, resp.StatusCode, string(body))
84+
if resp.StatusCode != http.StatusOK {
85+
return nil, fmt.Errorf("could not get quotastatus for blobstore %s", name)
8686
}
87-
return nil
87+
88+
var quotaStatus blobstore.QuotaStatus
89+
if err := json.Unmarshal(body, &quotaStatus); err != nil {
90+
return nil, fmt.Errorf("could not unmarshal of blobstore quotastatus: %v", err)
91+
}
92+
93+
return &quotaStatus, nil
8894
}

0 commit comments

Comments
 (0)