Skip to content

Commit 5f06ae1

Browse files
feat(storage): add update time in bucketAttrs (#10710)
Add update time field in bucketAttrs struct. Fixes #9361
1 parent 74cf45e commit 5f06ae1

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

‎storage/bucket.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ type BucketAttrs struct {
416416
// This field is read-only.
417417
Created time.Time
418418

419+
// Updated is the time at which the bucket was last modified.
420+
// This field is read-only.
421+
Updated time.Time
422+
419423
// VersioningEnabled reports whether this bucket has versioning enabled.
420424
VersioningEnabled bool
421425

@@ -824,6 +828,7 @@ func newBucket(b *raw.Bucket) (*BucketAttrs, error) {
824828
DefaultEventBasedHold: b.DefaultEventBasedHold,
825829
StorageClass: b.StorageClass,
826830
Created: convertTime(b.TimeCreated),
831+
Updated: convertTime(b.Updated),
827832
VersioningEnabled: b.Versioning != nil && b.Versioning.Enabled,
828833
ACL: toBucketACLRules(b.Acl),
829834
DefaultObjectACL: toObjectACLRules(b.DefaultObjectAcl),
@@ -861,6 +866,7 @@ func newBucketFromProto(b *storagepb.Bucket) *BucketAttrs {
861866
DefaultEventBasedHold: b.GetDefaultEventBasedHold(),
862867
StorageClass: b.GetStorageClass(),
863868
Created: b.GetCreateTime().AsTime(),
869+
Updated: b.GetUpdateTime().AsTime(),
864870
VersioningEnabled: b.GetVersioning().GetEnabled(),
865871
ACL: toBucketACLRulesFromProto(b.GetAcl()),
866872
DefaultObjectACL: toObjectACLRulesFromProto(b.GetDefaultObjectAcl()),

‎storage/bucket_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ func TestNewBucket(t *testing.T) {
605605
Metageneration: 3,
606606
StorageClass: "sc",
607607
TimeCreated: "2017-10-23T04:05:06Z",
608+
Updated: "2024-08-21T17:24:53Z",
608609
Versioning: &raw.BucketVersioning{Enabled: true},
609610
Labels: labels,
610611
Billing: &raw.BucketBilling{RequesterPays: true},
@@ -676,6 +677,7 @@ func TestNewBucket(t *testing.T) {
676677
MetaGeneration: 3,
677678
StorageClass: "sc",
678679
Created: time.Date(2017, 10, 23, 4, 5, 6, 0, time.UTC),
680+
Updated: time.Date(2024, 8, 21, 17, 24, 53, 0, time.UTC),
679681
VersioningEnabled: true,
680682
Labels: labels,
681683
Etag: "Zkyw9ACJZUvcYmlFaKGChzhmtnE/dt1zHSfweiWpwzdGsqXwuJZqiD0",
@@ -767,6 +769,7 @@ func TestNewBucketFromProto(t *testing.T) {
767769
Rpo: rpoAsyncTurbo,
768770
Metageneration: int64(39),
769771
CreateTime: toProtoTimestamp(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)),
772+
UpdateTime: toProtoTimestamp(time.Date(2024, 1, 2, 3, 4, 5, 6, time.UTC)),
770773
Labels: map[string]string{"label": "value"},
771774
Cors: []*storagepb.Bucket_Cors{
772775
{
@@ -820,6 +823,7 @@ func TestNewBucketFromProto(t *testing.T) {
820823
RPO: RPOAsyncTurbo,
821824
MetaGeneration: 39,
822825
Created: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
826+
Updated: time.Date(2024, 1, 2, 3, 4, 5, 6, time.UTC),
823827
Labels: map[string]string{"label": "value"},
824828
CORS: []CORS{
825829
{

‎storage/integration_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ func TestIntegration_BucketUpdate(t *testing.T) {
589589
if !testutil.Equal(attrs.Labels, wantLabels) {
590590
t.Fatalf("add labels: got %v, want %v", attrs.Labels, wantLabels)
591591
}
592+
if !attrs.Created.Before(attrs.Updated) {
593+
t.Errorf("got attrs.Updated %v before attrs.Created %v, want Attrs.Updated to be after", attrs.Updated, attrs.Created)
594+
}
592595

593596
// Turn off versioning again; add and remove some more labels.
594597
ua = BucketAttrsToUpdate{VersioningEnabled: false}
@@ -607,6 +610,9 @@ func TestIntegration_BucketUpdate(t *testing.T) {
607610
if !testutil.Equal(attrs.Labels, wantLabels) {
608611
t.Fatalf("got %v, want %v", attrs.Labels, wantLabels)
609612
}
613+
if !attrs.Created.Before(attrs.Updated) {
614+
t.Errorf("got attrs.Updated %v before attrs.Created %v, want Attrs.Updated to be after", attrs.Updated, attrs.Created)
615+
}
610616

611617
// Configure a lifecycle
612618
wantLifecycle := Lifecycle{
@@ -626,6 +632,9 @@ func TestIntegration_BucketUpdate(t *testing.T) {
626632
if !testutil.Equal(attrs.Lifecycle, wantLifecycle) {
627633
t.Fatalf("got %v, want %v", attrs.Lifecycle, wantLifecycle)
628634
}
635+
if !attrs.Created.Before(attrs.Updated) {
636+
t.Errorf("got attrs.Updated %v before attrs.Created %v, want Attrs.Updated to be after", attrs.Updated, attrs.Created)
637+
}
629638
// Check that StorageClass has "STANDARD" value for unset field by default
630639
// before passing new value.
631640
wantStorageClass := "STANDARD"
@@ -638,6 +647,9 @@ func TestIntegration_BucketUpdate(t *testing.T) {
638647
if !testutil.Equal(attrs.StorageClass, wantStorageClass) {
639648
t.Fatalf("got %v, want %v", attrs.StorageClass, wantStorageClass)
640649
}
650+
if !attrs.Created.Before(attrs.Updated) {
651+
t.Errorf("got attrs.Updated %v before attrs.Created %v, want Attrs.Updated to be after", attrs.Updated, attrs.Created)
652+
}
641653

642654
// Empty update should succeed without changing the bucket.
643655
gotAttrs, err := b.Update(ctx, BucketAttrsToUpdate{})
@@ -647,6 +659,9 @@ func TestIntegration_BucketUpdate(t *testing.T) {
647659
if !testutil.Equal(attrs, gotAttrs) {
648660
t.Fatalf("empty update: got %v, want %v", gotAttrs, attrs)
649661
}
662+
if !attrs.Created.Before(attrs.Updated) {
663+
t.Errorf("got attrs.Updated %v before attrs.Created %v, want Attrs.Updated to be after", attrs.Updated, attrs.Created)
664+
}
650665
})
651666
}
652667

0 commit comments

Comments
 (0)