From 9011340c3fe5c70853c2390148f0c24b33f012d5 Mon Sep 17 00:00:00 2001 From: Aleksandra Bogoslavetc Date: Thu, 15 Oct 2020 17:13:24 +0300 Subject: [PATCH 1/4] feat(storage): add missing StorageClass --- storage/bucket.go | 11 +++++++++++ storage/bucket_test.go | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/storage/bucket.go b/storage/bucket.go index 19221168f90..e3275819518 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -661,6 +661,14 @@ type BucketAttrsToUpdate struct { // for more information. UniformBucketLevelAccess *UniformBucketLevelAccess + // StorageClass is the default storage class of the bucket. This defines + // how objects in the bucket are stored and determines the SLA + // and the cost of storage. Typical values are "STANDARD", "NEARLINE", + // "COLDLINE" and "ARCHIVE". Defaults to "STANDARD". + // See https://cloud.google.com/storage/docs/storage-classes for all + // valid values. + StorageClass string + // If set, updates the retention policy of the bucket. Using // RetentionPolicy.RetentionPeriod = 0 will delete the existing policy. // @@ -801,6 +809,9 @@ func (ua *BucketAttrsToUpdate) toRawBucket() *raw.Bucket { rb.DefaultObjectAcl = nil rb.ForceSendFields = append(rb.ForceSendFields, "DefaultObjectAcl") } + if ua.StorageClass != "" { + rb.StorageClass = ua.StorageClass + } if ua.setLabels != nil || ua.deleteLabels != nil { rb.Labels = map[string]string{} for k, v := range ua.setLabels { diff --git a/storage/bucket_test.go b/storage/bucket_test.go index ff92e85fade..123e319a84e 100644 --- a/storage/bucket_test.go +++ b/storage/bucket_test.go @@ -268,8 +268,9 @@ func TestBucketAttrsToUpdateToRawBucket(t *testing.T) { }, }, }, - Logging: &BucketLogging{LogBucket: "lb", LogObjectPrefix: "p"}, - Website: &BucketWebsite{MainPageSuffix: "mps", NotFoundPage: "404"}, + Logging: &BucketLogging{LogBucket: "lb", LogObjectPrefix: "p"}, + Website: &BucketWebsite{MainPageSuffix: "mps", NotFoundPage: "404"}, + StorageClass: "NEARLINE", } au.SetLabel("a", "foo") au.DeleteLabel("b") @@ -308,6 +309,7 @@ func TestBucketAttrsToUpdateToRawBucket(t *testing.T) { }, Logging: &raw.BucketLogging{LogBucket: "lb", LogObjectPrefix: "p"}, Website: &raw.BucketWebsite{MainPageSuffix: "mps", NotFoundPage: "404"}, + StorageClass: "NEARLINE", ForceSendFields: []string{"DefaultEventBasedHold", "Lifecycle"}, } if msg := testutil.Diff(got, want); msg != "" { From 54aebf1ec55c7b8d8551041cd5265558b593f9cb Mon Sep 17 00:00:00 2001 From: Aleksandra Bogoslavetc Date: Thu, 15 Oct 2020 17:43:27 +0300 Subject: [PATCH 2/4] check StorageClass in update integration test --- storage/integration_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/storage/integration_test.go b/storage/integration_test.go index efa43dbcf3a..fa0ea5017fd 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -351,7 +351,7 @@ func TestIntegration_BucketUpdate(t *testing.T) { t.Fatalf("got %v, want %v", attrs.Labels, wantLabels) } - // Turn off versioning again; add and remove some more labels. + // Turn off versioning again; add and remove some more labels. ua = BucketAttrsToUpdate{VersioningEnabled: false} ua.SetLabel("l1", "v2") // update ua.SetLabel("new", "new") // create @@ -383,6 +383,17 @@ func TestIntegration_BucketUpdate(t *testing.T) { if !testutil.Equal(attrs.Lifecycle, wantLifecycle) { t.Fatalf("got %v, want %v", attrs.Lifecycle, wantLifecycle) } + // Check that StorageClass has "STANDARD" for unset field. + wantStorageClass := "STANDARD" + if !testutil.Equal(attrs.StorageClass, wantStorageClass) { + t.Fatalf("got %v, want %v", attrs.StorageClass, wantStorageClass) + } + wantStorageClass = "NEARLINE" + ua = BucketAttrsToUpdate{StorageClass: wantStorageClass} + attrs = h.mustUpdateBucket(b, ua) + if !testutil.Equal(attrs.StorageClass, wantStorageClass) { + t.Fatalf("got %v, want %v", attrs.StorageClass, wantStorageClass) + } } func TestIntegration_BucketPolicyOnly(t *testing.T) { From d6f8d42ce2872727135a0ab6c535665554fcca7f Mon Sep 17 00:00:00 2001 From: Aleksandra Bogoslavetc Date: Thu, 15 Oct 2020 18:43:24 +0300 Subject: [PATCH 3/4] fix --- storage/bucket.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/storage/bucket.go b/storage/bucket.go index e3275819518..5ada8cc81c8 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -809,9 +809,7 @@ func (ua *BucketAttrsToUpdate) toRawBucket() *raw.Bucket { rb.DefaultObjectAcl = nil rb.ForceSendFields = append(rb.ForceSendFields, "DefaultObjectAcl") } - if ua.StorageClass != "" { - rb.StorageClass = ua.StorageClass - } + rb.StorageClass = ua.StorageClass if ua.setLabels != nil || ua.deleteLabels != nil { rb.Labels = map[string]string{} for k, v := range ua.setLabels { From 1f7b0b7e39b2e6bcd2deb7e16849de642ffdfef9 Mon Sep 17 00:00:00 2001 From: Aleksandra Bogoslavetc Date: Fri, 16 Oct 2020 15:27:25 +0300 Subject: [PATCH 4/4] made the comment more clear --- storage/integration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/integration_test.go b/storage/integration_test.go index fa0ea5017fd..66e67c038e0 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -383,7 +383,8 @@ func TestIntegration_BucketUpdate(t *testing.T) { if !testutil.Equal(attrs.Lifecycle, wantLifecycle) { t.Fatalf("got %v, want %v", attrs.Lifecycle, wantLifecycle) } - // Check that StorageClass has "STANDARD" for unset field. + // Check that StorageClass has "STANDARD" value for unset field by default + // before passing new value. wantStorageClass := "STANDARD" if !testutil.Equal(attrs.StorageClass, wantStorageClass) { t.Fatalf("got %v, want %v", attrs.StorageClass, wantStorageClass)