frostfs-sdk-go/container/test/generate.go
Leonard Lyubich 3b15a01327 [#225] container/acl: Fix minor places
Make test value generator to be random as documented. Add `default`
keyword to switch-case to avoid linter comments.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2022-06-23 11:05:32 +03:00

59 lines
1.4 KiB
Go

package containertest
import (
"math/rand"
"github.com/nspcc-dev/neofs-sdk-go/container"
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
netmaptest "github.com/nspcc-dev/neofs-sdk-go/netmap/test"
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
versiontest "github.com/nspcc-dev/neofs-sdk-go/version/test"
)
// Attribute returns random container.Attribute.
func Attribute() *container.Attribute {
x := container.NewAttribute()
x.SetKey("key")
x.SetValue("value")
return x
}
// Attributes returns random container.Attributes.
func Attributes() container.Attributes {
return container.Attributes{*Attribute(), *Attribute()}
}
// Container returns random container.Container.
func Container() *container.Container {
x := container.New()
ver := versiontest.Version()
x.SetVersion(&ver)
x.SetAttributes(Attributes())
x.SetOwnerID(usertest.ID())
x.SetBasicACL(BasicACL())
p := netmaptest.PlacementPolicy()
x.SetPlacementPolicy(&p)
return x
}
// UsedSpaceAnnouncement returns random container.UsedSpaceAnnouncement.
func UsedSpaceAnnouncement() *container.UsedSpaceAnnouncement {
x := container.NewAnnouncement()
x.SetContainerID(cidtest.ID())
x.SetEpoch(55)
x.SetUsedSpace(999)
return x
}
// BasicACL returns random acl.Basic.
func BasicACL() (x acl.Basic) {
x.FromBits(rand.Uint32())
return
}