2024-08-12 11:22:56 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"crypto/md5"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/xml"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
2024-09-27 09:18:41 +00:00
|
|
|
apierr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
|
|
|
frosterr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/errors"
|
2024-08-12 11:22:56 +00:00
|
|
|
"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)
|
2024-09-27 09:18:41 +00:00
|
|
|
require.Equal(t, apierr.GetAPIError(apierr.ErrNoSuchLifecycleConfiguration), frosterr.UnwrapErr(err))
|
2024-08-12 11:22:56 +00:00
|
|
|
|
|
|
|
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)
|
2024-09-27 09:18:41 +00:00
|
|
|
require.Equal(t, apierr.GetAPIError(apierr.ErrNoSuchLifecycleConfiguration), frosterr.UnwrapErr(err))
|
2024-08-12 11:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ptr[T any](t T) *T {
|
|
|
|
return &t
|
|
|
|
}
|