Skip to content

Commit

Permalink
Persist created and updated time in compose
Browse files Browse the repository at this point in the history
Also use the correct time format.
  • Loading branch information
gaul committed Nov 26, 2024
1 parent 9e26890 commit ebc35c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,7 @@ func TestServiceClientComposeObject(t *testing.T) {
)
u32Checksum := uint32Checksum([]byte(source1Content))
hash := checksum.MD5Hash([]byte(source1Content))
now := time.Now()

objs := []Object{
{
Expand Down Expand Up @@ -2198,6 +2199,12 @@ func TestServiceClientComposeObject(t *testing.T) {
if attrs.ContentType != contentType {
t.Errorf("wrong content type\nwant %q\ngot %q", contentType, attrs.ContentType)
}
if now.After(attrs.Created) {
t.Errorf("wrong created time\nwant < %v\ngot: %v", now, attrs.Created)
}
if now.After(attrs.Updated) {
t.Errorf("wrong updated time\nwant < %v\ngot: %v", now, attrs.Updated)
}
if !bytes.Equal(attrs.MD5, expectedHash) {
t.Errorf("wrong hash returned\nwant %d\ngot %d", hash, attrs.MD5)
}
Expand Down
4 changes: 3 additions & 1 deletion internal/backend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,14 @@ func (s *storageFS) ComposeObject(bucketName string, objectNames []string, desti
sourceObjects = append(sourceObjects, obj)
}

now := time.Now().Format(timestampFormat)
dest := StreamingObject{
ObjectAttrs: ObjectAttrs{
BucketName: bucketName,
Name: destinationName,
ContentType: contentType,
Created: time.Now().String(),
Created: now,
Updated: now,
},
}

Expand Down
4 changes: 3 additions & 1 deletion internal/backend/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,14 @@ func (s *storageMemory) ComposeObject(bucketName string, objectNames []string, d
var dest Object
streamingDest, err := s.GetObject(bucketName, destinationName)
if err != nil {
now := time.Now().Format(timestampFormat)
dest = Object{
ObjectAttrs: ObjectAttrs{
BucketName: bucketName,
Name: destinationName,
ContentType: contentType,
Created: time.Now().String(),
Created: now,
Updated: now,
},
}
} else {
Expand Down

0 comments on commit ebc35c8

Please sign in to comment.