[#122] Add tests

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-08-13 17:13:14 +03:00
parent 43185de52a
commit 9c058a70fd
5 changed files with 960 additions and 332 deletions

View file

@ -9,7 +9,6 @@ import (
"time"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-s3-gw/api"
@ -19,18 +18,19 @@ import (
type (
// ObjectInfo holds S3 object data.
ObjectInfo struct {
id *object.ID
isDir bool
id *object.ID
bucketID *cid.ID
isDir bool
Bucket string
bucketID *cid.ID
Name string
Size int64
ContentType string
Created time.Time
HashSum string
Owner *owner.ID
Headers map[string]string
Bucket string
Name string
Size int64
ContentType string
Created time.Time
CreationEpoch uint64
HashSum string
Owner *owner.ID
Headers map[string]string
}
// ListObjectsInfo contains common fields of data for ListObjectsV1 and ListObjectsV2.
@ -54,19 +54,8 @@ type (
// ObjectVersionInfo stores info about objects versions.
ObjectVersionInfo struct {
Object *ObjectInfo
IsLatest bool
VersionID string
CreationEpoch uint64
}
// DeletedObjectInfo stores info about deleted versions of objects.
DeletedObjectInfo struct {
Owner *owner.ID
Key string
VersionID string
IsLatest bool
LastModified string
Object *ObjectInfo
IsLatest bool
}
// ListObjectVersionsInfo stores info and list of objects' versions.
@ -77,7 +66,7 @@ type (
NextKeyMarker string
NextVersionIDMarker string
Version []*ObjectVersionInfo
DeleteMarker []*DeletedObjectInfo
DeleteMarker []*ObjectVersionInfo
VersionIDMarker string
}
)
@ -137,29 +126,22 @@ func objectInfoFromMeta(bkt *BucketInfo, meta *object.Object, prefix, delimiter
}
return &ObjectInfo{
id: meta.ID(),
isDir: isDir,
id: meta.ID(),
bucketID: bkt.CID,
isDir: isDir,
Bucket: bkt.Name,
bucketID: bkt.CID,
Name: filename,
Created: creation,
ContentType: mimeType,
Headers: userHeaders,
Owner: meta.OwnerID(),
Size: size,
HashSum: meta.PayloadChecksum().String(),
Bucket: bkt.Name,
Name: filename,
Created: creation,
CreationEpoch: meta.CreationEpoch(),
ContentType: mimeType,
Headers: userHeaders,
Owner: meta.OwnerID(),
Size: size,
HashSum: meta.PayloadChecksum().String(),
}
}
func objectVersionInfoFromMeta(bkt *BucketInfo, meta *object.Object, prefix, delimiter string) *ObjectVersionInfo {
oi := objectInfoFromMeta(bkt, meta, prefix, delimiter)
if oi == nil {
return nil
}
return &ObjectVersionInfo{Object: oi, VersionID: meta.ID().String(), CreationEpoch: meta.CreationEpoch()}
}
func filenameFromObject(o *object.Object) string {
var name = o.ID().String()
for _, attr := range o.Attributes() {
@ -179,6 +161,9 @@ func NameFromString(name string) (string, string) {
// ID returns object ID from ObjectInfo.
func (o *ObjectInfo) ID() *object.ID { return o.id }
// Version returns object version from ObjectInfo.
func (o *ObjectInfo) Version() string { return o.id.String() }
// CID returns bucket ID from ObjectInfo.
func (o *ObjectInfo) CID() *cid.ID { return o.bucketID }