go-ceph/rgw/admin/caps_test.go
Anoop C S 2c47426469 rgw/admin: Remove 'ceph_preview' tags from test files
These are left overs from v0.13.0 and v0.17.0 releases where we missed
to remove preview tag when corresponding APIs were promoted to stable.

Signed-off-by: Anoop C S <anoopcs@cryptolab.net>
2022-12-19 18:20:48 +00:00

68 lines
2.2 KiB
Go

package admin
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func (suite *RadosGWTestSuite) TestCaps() {
suite.SetupConnection()
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, newDebugHTTPClient(http.DefaultClient))
assert.NoError(suite.T(), err)
suite.T().Run("create test user", func(t *testing.T) {
user, err := co.CreateUser(context.Background(), User{ID: "test", DisplayName: "test-user", Email: "test@example.com"})
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), "test", user.ID)
assert.Zero(suite.T(), len(user.Caps))
})
suite.T().Run("add caps to the user but user ID is empty", func(t *testing.T) {
_, err := co.AddUserCap(context.Background(), "", "users=read")
assert.Error(suite.T(), err)
assert.EqualError(suite.T(), err, errMissingUserID.Error())
})
suite.T().Run("add caps to the user but no cap is specified", func(t *testing.T) {
_, err := co.AddUserCap(context.Background(), "test", "")
assert.Error(suite.T(), err)
assert.EqualError(suite.T(), err, errMissingUserCap.Error())
})
suite.T().Run("add caps to the user, returns success", func(t *testing.T) {
usercap, err := co.AddUserCap(context.Background(), "test", "users=read")
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), "users", usercap[0].Type)
assert.Equal(suite.T(), "read", usercap[0].Perm)
})
suite.T().Run("remove caps from the user but user ID is empty", func(t *testing.T) {
_, err := co.RemoveUserCap(context.Background(), "", "users=read")
assert.Error(suite.T(), err)
assert.EqualError(suite.T(), err, errMissingUserID.Error())
})
suite.T().Run("remove caps from the user but no cap is specified", func(t *testing.T) {
_, err := co.RemoveUserCap(context.Background(), "test", "")
assert.Error(suite.T(), err)
assert.EqualError(suite.T(), err, errMissingUserCap.Error())
})
suite.T().Run("remove caps from the user returns success", func(t *testing.T) {
usercap, err := co.RemoveUserCap(context.Background(), "test", "users=read")
assert.NoError(suite.T(), err)
assert.Zero(suite.T(), len(usercap))
})
suite.T().Run("delete test user", func(t *testing.T) {
err := co.RemoveUser(context.Background(), User{ID: "test"})
assert.NoError(suite.T(), err)
})
}