Skip to content

Commit

Permalink
rgw/admin: Add tests for user bucket quota APIs
Browse files Browse the repository at this point in the history
Credits: Pavel Boev (https://github.com/R4scal)
Signed-off-by: Anoop C S <[email protected]>
  • Loading branch information
anoopcs9 authored and mergify[bot] committed Feb 6, 2024
1 parent 2f0bbfe commit 8cc709a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions rgw/admin/user_bucket_quota_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//go:build ceph_preview

package admin

import (
"context"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func (suite *RadosGWTestSuite) TestUserBucketQuota() {
suite.SetupConnection()
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, newDebugHTTPClient(http.DefaultClient))
assert.NoError(suite.T(), err)

usercaps := "users=read"
_, err = co.CreateUser(context.Background(), User{ID: "leseb", DisplayName: "This is leseb", Email: "[email protected]", UserCaps: usercaps})
assert.NoError(suite.T(), err)
defer func() {
err = co.RemoveUser(context.Background(), User{ID: "leseb"})
assert.NoError(suite.T(), err)
}()

suite.T().Run("set bucket quota without uid", func(t *testing.T) {
err := co.SetBucketQuota(context.Background(), QuotaSpec{})
assert.Error(suite.T(), err)
assert.EqualError(suite.T(), err, errMissingUserID.Error())
})

suite.T().Run("set bucket quota", func(t *testing.T) {
maxObjects := int64(101)
err := co.SetBucketQuota(context.Background(), QuotaSpec{UID: "leseb", MaxObjects: &maxObjects})
assert.NoError(suite.T(), err)
})

suite.T().Run("get bucket quota without uid", func(t *testing.T) {
_, err := co.GetBucketQuota(context.Background(), QuotaSpec{})
assert.Error(suite.T(), err)
assert.EqualError(suite.T(), err, errMissingUserID.Error())
})

suite.T().Run("get bucket quota", func(t *testing.T) {
q, err := co.GetBucketQuota(context.Background(), QuotaSpec{UID: "leseb"})
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), int64(101), *q.MaxObjects)
assert.Equal(suite.T(), false, *q.Enabled)
})
}

0 comments on commit 8cc709a

Please sign in to comment.