Skip to content

Commit

Permalink
layer: Fix internal tests
Browse files Browse the repository at this point in the history
In real NeoFS the complex object is constructing by the node using linking object, previous-id header, etc. For tests we use only the map and this step creates real object in this map.

Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed May 28, 2024
1 parent 77f4f97 commit f242f22
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions api/layer/neofs_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,39 @@ func (t *TestNeoFS) CreateObject(_ context.Context, prm PrmObjectCreate) (oid.ID
obj.WriteLink(*prm.Multipart.Link)
prm.Payload = bytes.NewReader(obj.Payload())
obj.SetPayloadSize(uint64(len(obj.Payload())))

var (
addr oid.Address
payload []byte
)

for _, e := range prm.Multipart.Link.Objects() {
addr = newAddress(prm.Container, e.ObjectID())
if partialObject, ok := t.objects[addr.EncodeToString()]; ok {
payload = append(payload, partialObject.Payload()...)
}
}

pid, isSet := prm.Multipart.HeaderObject.ID()
if !isSet {
return oid.ID{}, errors.New("HeaderObject id is not set")
}

realHeaderObj := object.New()
realHeaderObj.SetContainerID(prm.Container)
realHeaderObj.SetID(pid)
realHeaderObj.SetPayloadSize(uint64(len(payload)))
realHeaderObj.SetAttributes(attrs...)
realHeaderObj.SetCreationEpoch(t.currentEpoch)
realHeaderObj.SetOwnerID(&prm.Creator)
realHeaderObj.SetPayload(payload)

var h checksum.Checksum
checksum.Calculate(&h, checksum.SHA256, payload)
realHeaderObj.SetPayloadChecksum(h)

addr = newAddress(prm.Container, pid)
t.objects[addr.EncodeToString()] = realHeaderObj
}
}

Expand Down

0 comments on commit f242f22

Please sign in to comment.