@@ -295,18 +295,47 @@ Describe "New-GcsObject" {
295295 Remove-GcsObject $emptyObj
296296 }
297297
298+ It " should work with fixed-type metadata" {
299+ $obj = New-GcsObject $bucket " metadata-test" `
300+ - ContentEncoding " gzip" - ContentType " image/png"
301+ $obj.Metadata | Should BeNullOrEmpty
302+ $obj.ContentType | Should Be " image/png"
303+ $obj.ContentEncoding | Should Be " gzip"
304+ Remove-GcsObject $obj
305+ }
306+
307+ It " should work with fixed-type metadata through -Metadata parameter" {
308+ $obj = New-GcsObject $bucket " metadata-test" `
309+ - Metadata @ { " Content-Encoding" = " gzip" ; " Content-Type" = " image/png" }
310+ $obj.Metadata | Should BeNullOrEmpty
311+ $obj.ContentType | Should Be " image/png"
312+ $obj.ContentEncoding | Should Be " gzip"
313+ Remove-GcsObject $obj
314+ }
315+
298316 It " should write metadata" {
299317 $obj = New-GcsObject $bucket " metadata-test" `
300318 - Metadata @ { " alpha" = 1 ; " beta" = " two" ; " Content-Type" = " image/png" }
301- $obj.Metadata.Count = 3
319+ $obj.Metadata.Count = 2
302320 $obj.Metadata [" alpha" ] | Should Be 1
303321 $obj.Metadata [" beta" ] | Should Be " two"
304- $obj.Metadata [" Content-Type" ] | Should Be " image/png"
305322 # Content-Type can be set from metadata.
306323 $obj.ContentType | Should Be " image/png"
307324 Remove-GcsObject $obj
308325 }
309326
327+ It " should work with both fixed-type and custom metadata" {
328+ $obj = New-GcsObject $bucket " metadata-test" `
329+ - Metadata @ { " Content-Encoding" = " gzip" ; " Content-Type" = " image/png" ;
330+ " alpha" = 1 ; " beta" = " two" }
331+ $obj.Metadata.Count = 2
332+ $obj.Metadata [" alpha" ] | Should Be 1
333+ $obj.Metadata [" beta" ] | Should Be " two"
334+ $obj.ContentType | Should Be " image/png"
335+ $obj.ContentEncoding | Should Be " gzip"
336+ Remove-GcsObject $obj
337+ }
338+
310339 # Regression for a bug found while unit testing other scenarios.
311340 It " should write metadata when accepting content from pipeline" {
312341 $obj = " XXX" | New-GcsObject $bucket " metadata-test-2" `
@@ -316,13 +345,15 @@ Describe "New-GcsObject" {
316345 Remove-GcsObject $obj
317346 }
318347
319- It " will prefer the -ContentType parameter to -Metadata" {
348+ It " will prefer the fixed-type metadata parameter to -Metadata" {
320349 $obj = New-GcsObject $bucket " metadata-test" `
350+ - ContentLanguage " aa" `
321351 - ContentType " image/jpeg" `
322- - Metadata @ { " Content-Type" = " image/png" }
352+ - Metadata @ { " Content-Type" = " image/png" ; " Content-Language " = " en " }
323353 $obj.ContentType | Should Be " image/jpeg"
324- # It will also apply to the Metadata too.
325- $obj.Metadata [" Content-Type" ] | Should Be " image/jpeg"
354+ $obj.ContentLanguage | Should Be " aa"
355+ # It should not apply to the Metadata too.
356+ $obj.Metadata | Should BeNullOrEmpty
326357 Remove-GcsObject $obj
327358 }
328359
@@ -1151,7 +1182,7 @@ Describe "Write-GcsObject" {
11511182 Remove-GcsObject $bucket " acl-test"
11521183 }
11531184
1154- It " should not clobber existing metadata" {
1185+ It " should not clobber existing custom metadata" {
11551186 $orgObj = " original contents" | New-GcsObject $bucket " metadata-test" `
11561187 - Metadata @ { " one" = 1 ; " two" = 2 }
11571188 $orgObj.Metadata.Count | Should Be 2
@@ -1162,6 +1193,30 @@ Describe "Write-GcsObject" {
11621193 Remove-GcsObject $bucket " metadata-test"
11631194 }
11641195
1196+ It " should not clobber existing fixed-key metadata" {
1197+ $orgObj = " original contents" | New-GcsObject $bucket " metadata-test" `
1198+ - ContentEncoding " gzip" - ContentLanguage " aa"
1199+
1200+ $updatedObj = " new contents" | Write-GcsObject $bucket " metadata-test" `
1201+ - ContentLanguage " en"
1202+ $updatedObj.ContentLanguage | Should Be " en"
1203+ $updatedObj.ContentEncoding | Should Be " gzip"
1204+
1205+ Remove-GcsObject $bucket " metadata-test"
1206+ }
1207+
1208+ It " should update fixed-key metadata to null" {
1209+ $orgObj = " original contents" | New-GcsObject $bucket " metadata-test" `
1210+ - ContentEncoding " gzip" - ContentLanguage " aa"
1211+
1212+ $updatedObj = " new contents" | Write-GcsObject $bucket " metadata-test" `
1213+ - ContentLanguage $null - ContentEncoding $null
1214+ $updatedObj.ContentLanguage | Should BeNullOrEmpty
1215+ $updatedObj.ContentEncoding | Should BeNullOrEmpty
1216+
1217+ Remove-GcsObject $bucket " metadata-test"
1218+ }
1219+
11651220 It " should merge Metadata updates" {
11661221 $step1 = " XXX" | New-GcsObject $bucket " metadata-test2" `
11671222 - Metadata @ { " alpha" = 1 ; " beta" = 2 ; " gamma" = 3 }
@@ -1183,17 +1238,36 @@ Describe "Write-GcsObject" {
11831238 Remove-GcsObject $bucket " metadata-test2"
11841239 }
11851240
1186- It " should give precidence to the ContentType parameter" {
1241+ It " should use fixed-key parameter in -Metadata parameter" {
1242+ # Where Write-Gcs object creates a new object (-Force)
1243+ $newObjectCase = " XXX" | Write-GcsObject $bucket " content-type-test" `
1244+ - ContentType " image/png" - ContentLanguage " en" `
1245+ - Metadata @ { " Content-Type" = " image/jpeg" } - Force
1246+ $newObjectCase.ContentType | Should Be " image/png"
1247+ $newObjectCase.ContentLanguage | Should Be " en"
1248+
1249+ $both = " XXX" | Write-GcsObject $bucket " content-type-test" `
1250+ - Metadata @ { " Content-Type" = " test/beta" ; " Content-Language" = " aa" }
1251+ $both.ContentType | Should Be " test/beta"
1252+ $both.ContentLanguage | Should Be " aa"
1253+
1254+ Remove-GcsObject $bucket " content-type-test"
1255+ }
1256+
1257+ It " should give precedence to the fixed type parameter" {
11871258 # Where Write-Gcs object creates a new object (-Force)
11881259 $newObjectCase = " XXX" | Write-GcsObject $bucket " content-type-test" `
1189- - ContentType " image/png" - Metadata @ { " Content-Type " = " image/jpeg " } `
1190- - Force
1260+ - ContentType " image/png" - ContentLanguage " en " `
1261+ - Metadata @ { " Content-Type " = " image/jpeg " } - Force
11911262 $newObjectCase.ContentType | Should Be " image/png"
1263+ $newObjectCase.ContentLanguage | Should Be " en"
11921264
1193- # Where Write-Gcs has both ContentType and a Metadata value.
1265+ # Where Write-Gcs has both ContentType, ContentLanguage and a Metadata value.
11941266 $both = " XXX" | Write-GcsObject $bucket " content-type-test" `
1195- - ContentType " test/alpha" - Metadata @ { " Content-Type" = " test/beta" }
1267+ - ContentType " test/alpha" - ContentLanguage " aa" `
1268+ - Metadata @ { " Content-Type" = " test/beta" ; " Content-Language" = " bb" }
11961269 $both.ContentType | Should Be " test/alpha"
1270+ $both.ContentLanguage | Should Be " aa"
11971271
11981272 Remove-GcsObject $bucket " content-type-test"
11991273 }
0 commit comments