2022-03-05 14:21:16 +00:00
|
|
|
package object_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-09-16 11:59:30 +00:00
|
|
|
v2container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
2023-03-07 11:20:03 +00:00
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2024-09-16 11:59:30 +00:00
|
|
|
objecttest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/test"
|
2023-03-07 11:20:03 +00:00
|
|
|
usertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user/test"
|
2022-03-05 14:21:16 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInitCreation(t *testing.T) {
|
|
|
|
var o object.Object
|
2022-04-11 16:25:14 +00:00
|
|
|
cnr := cidtest.ID()
|
2023-11-21 08:35:10 +00:00
|
|
|
own := usertest.ID()
|
2022-03-05 14:21:16 +00:00
|
|
|
|
|
|
|
object.InitCreation(&o, object.RequiredFields{
|
|
|
|
Container: cnr,
|
|
|
|
Owner: own,
|
|
|
|
})
|
|
|
|
|
2022-04-12 16:23:16 +00:00
|
|
|
cID, set := o.ContainerID()
|
|
|
|
require.True(t, set)
|
|
|
|
require.Equal(t, cnr, cID)
|
2023-11-21 08:35:10 +00:00
|
|
|
require.Equal(t, own, o.OwnerID())
|
2022-03-05 14:21:16 +00:00
|
|
|
}
|
2024-09-16 11:59:30 +00:00
|
|
|
|
|
|
|
func Test_Attributes(t *testing.T) {
|
|
|
|
obj := objecttest.Object()
|
|
|
|
|
|
|
|
t.Run("get user attributes", func(t *testing.T) {
|
|
|
|
// See how we create a test object. It's created with two attributes.
|
|
|
|
require.Len(t, obj.UserAttributes(), 2)
|
|
|
|
})
|
|
|
|
|
|
|
|
userAttrs := obj.UserAttributes()
|
|
|
|
|
|
|
|
sysAttr := *object.NewAttribute()
|
|
|
|
sysAttr.SetKey(v2container.SysAttributePrefix + "key")
|
|
|
|
sysAttr.SetValue("value")
|
|
|
|
|
|
|
|
attr := append(userAttrs, sysAttr)
|
|
|
|
obj.SetAttributes(attr...)
|
|
|
|
|
|
|
|
t.Run("get attributes", func(t *testing.T) {
|
|
|
|
require.ElementsMatch(t, obj.UserAttributes(), userAttrs)
|
|
|
|
require.ElementsMatch(t, obj.Attributes(), attr)
|
|
|
|
})
|
|
|
|
}
|