forked from TrueCloudLab/frostfs-s3-gw
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package layer
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/md5"
|
|
"encoding/base64"
|
|
"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"
|
|
"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,
|
|
LifecycleReader: bytes.NewReader(lifecycleBytes),
|
|
MD5Hash: base64.StdEncoding.EncodeToString(hash.Sum(nil)),
|
|
})
|
|
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 ptr[T any](t T) *T {
|
|
return &t
|
|
}
|