Skip to content

Commit

Permalink
backend: always set StorageClass
Browse files Browse the repository at this point in the history
Closes #1871.
  • Loading branch information
fsouza committed Jan 10, 2025
1 parent 491167a commit f534f9c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type objectTestCases []struct {
func getObjectTestCases() objectTestCases {
const (
bucketName = "some-bucket"
storageClass = "COLDLINE"
content = "some nice content"
contentType = "text/plain; charset=utf-8"
contentEncoding = "gzip"
Expand Down Expand Up @@ -119,6 +118,7 @@ func getObjectTestCases() objectTestCases {
Crc32c: checksum.EncodedChecksum(uint32ToBytes(u32Checksum)),
Md5Hash: checksum.EncodedHash(hash),
Metadata: map[string]string{"MetaHeader": metaValue},
StorageClass: "COLDLINE",
},
},
},
Expand Down Expand Up @@ -195,6 +195,13 @@ func checkObjectAttrs(testObj Object, attrs *storage.ObjectAttrs, t *testing.T)
if attrs.ContentLanguage != testObj.ContentLanguage {
t.Errorf("wrong content language\nwant %q\ngot %q", testObj.ContentLanguage, attrs.ContentLanguage)
}
expectedStorageClass := testObj.StorageClass
if expectedStorageClass == "" {
expectedStorageClass = "STANDARD"
}
if attrs.StorageClass != expectedStorageClass {
t.Errorf("wrong storage class\nwant %q\ngot %q", expectedStorageClass, attrs.StorageClass)
}
if testObj.Content != nil && attrs.Size != int64(len(testObj.Content)) {
t.Errorf("wrong size returned\nwant %d\ngot %d", len(testObj.Content), attrs.Size)
}
Expand Down
3 changes: 3 additions & 0 deletions internal/backend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ func (s *storageFS) CreateObject(obj StreamingObject, conditions Conditions) (St
if obj.Etag == "" {
obj.Etag = obj.Md5Hash
}
if obj.StorageClass == "" {
obj.StorageClass = "STANDARD"
}

// TODO: Handle if metadata is not present more gracefully?
encoded, err := json.Marshal(obj.ObjectAttrs)
Expand Down
3 changes: 3 additions & 0 deletions internal/backend/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (bm *bucketInMemory) addObject(obj Object) Object {
if obj.Size == 0 {
obj.Size = int64(len(obj.Content))
}
if obj.StorageClass == "" {
obj.StorageClass = "STANDARD"
}
obj.Generation = getNewGenerationIfZero(obj.Generation)
index := findObject(obj, bm.activeObjects, false)
if index >= 0 {
Expand Down

0 comments on commit f534f9c

Please sign in to comment.