All checks were successful
/ DCO (pull_request) Successful in 36s
/ Vulncheck (pull_request) Successful in 1m10s
/ Builds (pull_request) Successful in 1m38s
/ OCI image (pull_request) Successful in 2m13s
/ Lint (pull_request) Successful in 2m24s
/ Tests (pull_request) Successful in 1m20s
/ Vulncheck (push) Successful in 1m9s
/ Builds (push) Successful in 58s
/ OCI image (push) Successful in 1m58s
/ Lint (push) Successful in 2m5s
/ Tests (push) Successful in 1m15s
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
109 lines
2.9 KiB
Go
109 lines
2.9 KiB
Go
package layer
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/xml"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
|
apierr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
|
frosterr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/errors"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestBucketLifecycle(t *testing.T) {
|
|
tc := prepareContext(t)
|
|
|
|
lifecycle := &data.LifecycleConfiguration{
|
|
XMLName: xml.Name{
|
|
Space: `http://s3.amazonaws.com/doc/2006-03-01/`,
|
|
Local: "LifecycleConfiguration",
|
|
},
|
|
Rules: []data.LifecycleRule{
|
|
{
|
|
Status: data.LifecycleStatusEnabled,
|
|
Expiration: &data.LifecycleExpiration{
|
|
Days: ptr(21),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
lifecycleBytes, err := xml.Marshal(lifecycle)
|
|
require.NoError(t, err)
|
|
hash := md5.New()
|
|
hash.Write(lifecycleBytes)
|
|
|
|
_, err = tc.layer.GetBucketLifecycleConfiguration(tc.ctx, tc.bktInfo)
|
|
require.Equal(t, apierr.GetAPIError(apierr.ErrNoSuchLifecycleConfiguration), frosterr.UnwrapErr(err))
|
|
|
|
err = tc.layer.DeleteBucketLifecycleConfiguration(tc.ctx, tc.bktInfo)
|
|
require.NoError(t, err)
|
|
|
|
err = tc.layer.PutBucketLifecycleConfiguration(tc.ctx, &PutBucketLifecycleParams{
|
|
BktInfo: tc.bktInfo,
|
|
LifecycleCfg: lifecycle,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
cfg, err := tc.layer.GetBucketLifecycleConfiguration(tc.ctx, tc.bktInfo)
|
|
require.NoError(t, err)
|
|
require.Equal(t, *lifecycle, *cfg)
|
|
|
|
err = tc.layer.DeleteBucketLifecycleConfiguration(tc.ctx, tc.bktInfo)
|
|
require.NoError(t, err)
|
|
|
|
_, err = tc.layer.GetBucketLifecycleConfiguration(tc.ctx, tc.bktInfo)
|
|
require.Equal(t, apierr.GetAPIError(apierr.ErrNoSuchLifecycleConfiguration), frosterr.UnwrapErr(err))
|
|
}
|
|
|
|
func TestLifecycleCopiesNumber(t *testing.T) {
|
|
tc := prepareCORSContext(t)
|
|
|
|
lifecycle := &data.LifecycleConfiguration{
|
|
XMLName: xml.Name{
|
|
Space: `http://s3.amazonaws.com/doc/2006-03-01/`,
|
|
Local: "LifecycleConfiguration",
|
|
},
|
|
Rules: []data.LifecycleRule{
|
|
{
|
|
Status: data.LifecycleStatusEnabled,
|
|
Expiration: &data.LifecycleExpiration{
|
|
Days: ptr(21),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
copies := []uint32{2, 0}
|
|
|
|
err := tc.layer.PutBucketLifecycleConfiguration(tc.ctx, &PutBucketLifecycleParams{
|
|
BktInfo: tc.bktInfo,
|
|
LifecycleCfg: lifecycle,
|
|
CopiesNumbers: copies,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
cfg, err := tc.layer.GetBucketLifecycleConfiguration(tc.ctx, tc.bktInfo)
|
|
require.NoError(t, err)
|
|
require.Equal(t, *lifecycle, *cfg)
|
|
|
|
objs := tc.testFrostFS.Objects()
|
|
require.Len(t, objs, 1)
|
|
|
|
require.EqualValues(t, copies, tc.testFrostFS.CopiesNumbers(addrFromObject(objs[0]).EncodeToString()))
|
|
}
|
|
|
|
func ptr[T any](t T) *T {
|
|
return &t
|
|
}
|
|
func addrFromObject(obj *object.Object) oid.Address {
|
|
var addr oid.Address
|
|
cnrID, _ := obj.ContainerID()
|
|
objID, _ := obj.ID()
|
|
|
|
addr.SetContainer(cnrID)
|
|
addr.SetObject(objID)
|
|
|
|
return addr
|
|
}
|