2021-05-12 12:38:18 +00:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2021-07-27 16:21:53 +00:00
|
|
|
"net/http"
|
2021-05-12 12:38:18 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-05-17 17:06:28 +00:00
|
|
|
"github.com/ceph/go-ceph/internal/util"
|
2021-05-12 12:38:18 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (suite *RadosGWTestSuite) TestBucket() {
|
|
|
|
suite.SetupConnection()
|
2021-07-27 16:21:53 +00:00
|
|
|
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, newDebugHTTPClient(http.DefaultClient))
|
2021-05-12 12:38:18 +00:00
|
|
|
assert.NoError(suite.T(), err)
|
|
|
|
|
2021-06-04 11:22:52 +00:00
|
|
|
s3, err := newS3Agent(suite.accessKey, suite.secretKey, suite.endpoint, true)
|
|
|
|
assert.NoError(suite.T(), err)
|
|
|
|
|
|
|
|
err = s3.createBucket(suite.bucketTestName)
|
|
|
|
assert.NoError(suite.T(), err)
|
|
|
|
|
2021-05-12 12:38:18 +00:00
|
|
|
suite.T().Run("list buckets", func(t *testing.T) {
|
|
|
|
buckets, err := co.ListBuckets(context.Background())
|
|
|
|
assert.NoError(suite.T(), err)
|
2021-06-04 11:22:52 +00:00
|
|
|
assert.Equal(suite.T(), 1, len(buckets))
|
2021-05-12 12:38:18 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
suite.T().Run("info non-existing bucket", func(t *testing.T) {
|
|
|
|
_, err := co.GetBucketInfo(context.Background(), Bucket{Bucket: "foo"})
|
|
|
|
assert.Error(suite.T(), err)
|
|
|
|
assert.True(suite.T(), errors.Is(err, ErrNoSuchBucket), err)
|
|
|
|
})
|
|
|
|
|
2021-06-04 11:22:52 +00:00
|
|
|
suite.T().Run("info existing bucket", func(t *testing.T) {
|
|
|
|
_, err := co.GetBucketInfo(context.Background(), Bucket{Bucket: suite.bucketTestName})
|
|
|
|
assert.NoError(suite.T(), err)
|
|
|
|
})
|
|
|
|
|
2023-06-02 05:53:36 +00:00
|
|
|
suite.T().Run("get policy non-existing bucket", func(t *testing.T) {
|
|
|
|
_, err := co.GetBucketPolicy(context.Background(), Bucket{Bucket: "foo"})
|
|
|
|
assert.Error(suite.T(), err)
|
|
|
|
assert.True(suite.T(), errors.Is(err, ErrNoSuchKey), err)
|
|
|
|
})
|
|
|
|
|
|
|
|
suite.T().Run("get policy existing bucket", func(t *testing.T) {
|
|
|
|
_, err := co.GetBucketPolicy(context.Background(), Bucket{Bucket: suite.bucketTestName})
|
|
|
|
assert.NoError(suite.T(), err)
|
|
|
|
})
|
|
|
|
|
2021-06-04 11:22:52 +00:00
|
|
|
suite.T().Run("remove bucket", func(t *testing.T) {
|
|
|
|
err := co.RemoveBucket(context.Background(), Bucket{Bucket: suite.bucketTestName})
|
|
|
|
assert.NoError(suite.T(), err)
|
|
|
|
})
|
|
|
|
|
|
|
|
suite.T().Run("list bucket is now zero", func(t *testing.T) {
|
|
|
|
buckets, err := co.ListBuckets(context.Background())
|
|
|
|
assert.NoError(suite.T(), err)
|
|
|
|
assert.Equal(suite.T(), 0, len(buckets))
|
|
|
|
})
|
|
|
|
|
2021-05-12 12:38:18 +00:00
|
|
|
suite.T().Run("remove non-existing bucket", func(t *testing.T) {
|
|
|
|
err := co.RemoveBucket(context.Background(), Bucket{Bucket: "foo"})
|
|
|
|
assert.Error(suite.T(), err)
|
2022-05-17 17:06:28 +00:00
|
|
|
if util.CurrentCephVersion() <= util.CephOctopus {
|
|
|
|
assert.True(suite.T(), errors.Is(err, ErrNoSuchKey))
|
|
|
|
} else {
|
|
|
|
assert.True(suite.T(), errors.Is(err, ErrNoSuchBucket))
|
|
|
|
}
|
2021-05-12 12:38:18 +00:00
|
|
|
})
|
|
|
|
}
|