diff --git a/fakestorage/object_test.go b/fakestorage/object_test.go index 60fcd448bc..6ed1fee528 100644 --- a/fakestorage/object_test.go +++ b/fakestorage/object_test.go @@ -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" @@ -119,6 +118,7 @@ func getObjectTestCases() objectTestCases { Crc32c: checksum.EncodedChecksum(uint32ToBytes(u32Checksum)), Md5Hash: checksum.EncodedHash(hash), Metadata: map[string]string{"MetaHeader": metaValue}, + StorageClass: "COLDLINE", }, }, }, @@ -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) } diff --git a/internal/backend/fs.go b/internal/backend/fs.go index b8f226d213..d915ac1b7a 100644 --- a/internal/backend/fs.go +++ b/internal/backend/fs.go @@ -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) diff --git a/internal/backend/memory.go b/internal/backend/memory.go index 17b6480ea1..fa54d9101c 100644 --- a/internal/backend/memory.go +++ b/internal/backend/memory.go @@ -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 {