Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional bucket response attributes #1258

Merged
merged 3 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions fakestorage/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ func TestServerClientBucketAttrs(t *testing.T) {
if attrs.Created.Before(startTime.Truncate(time.Second)) || time.Now().Before(attrs.Created) {
t.Errorf("expecting bucket creation date between test start time %v and now %v, got %v", startTime, time.Now(), attrs.Created)
}
// TODO: Test `attrs.Updated` as soon as it is available in the [`storage.BucketAttrs`][1] type
// (not available as of cloud.google.com/go/storage v1.31.0)
// [1]: https://pkg.go.dev/cloud.google.com/go/storage#BucketAttrs
if attrs.StorageClass != "STANDARD" {
t.Errorf("wrong bucket storage class returned\nwant %q\ngot %q", "STANDARD", attrs.StorageClass)
}
})
}

Expand Down
4 changes: 4 additions & 0 deletions fakestorage/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ type bucketResponse struct {
Name string `json:"name"`
Versioning *bucketVersioning `json:"versioning,omitempty"`
TimeCreated string `json:"timeCreated,omitempty"`
Updated string `json:"updated,omitempty"`
Location string `json:"location,omitempty"`
StorageClass string `json:"storageClass,omitempty"`
}

type bucketVersioning struct {
Expand All @@ -58,7 +60,9 @@ func newBucketResponse(bucket backend.Bucket, location string) bucketResponse {
DefaultEventBasedHold: bucket.DefaultEventBasedHold,
Versioning: &bucketVersioning{bucket.VersioningEnabled},
TimeCreated: formatTime(bucket.TimeCreated),
Updated: formatTime(bucket.TimeCreated), // not tracking update times yet, reporting `updated` = `timeCreated`
Location: location,
StorageClass: "STANDARD",
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ func TestBucketAttrsStoreRetrieveUpdate(t *testing.T) {
}

func TestBucketCreateGetListDelete(t *testing.T) {
startTime := time.Now()
testForStorageBackends(t, func(t *testing.T, storage Storage) {
buckets, err := storage.ListBuckets()
if err != nil {
Expand Down Expand Up @@ -344,6 +345,9 @@ func TestBucketCreateGetListDelete(t *testing.T) {
if buckets[0].Name != bucket.Name {
t.Errorf("listed bucket has unexpected name. Expected %s, actual: %v", bucket.Name, buckets[0].Name)
}
if buckets[0].TimeCreated.Before(startTime.Truncate(time.Second)) || time.Now().Before(buckets[0].TimeCreated) {
t.Errorf("listed bucket has unexpected creation time. Expected between test start time %v and now %v, actual: %v", startTime, time.Now(), buckets[0].TimeCreated)
}
err = storage.DeleteBucket(bucket.Name)
if err != nil {
t.Fatal(err)
Expand Down
6 changes: 5 additions & 1 deletion internal/backend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ func (s *storageFS) ListBuckets() ([]Bucket, error) {
if err != nil {
return nil, fmt.Errorf("failed to unescape object name %s: %w", info.Name(), err)
}
buckets = append(buckets, Bucket{Name: unescaped})
fileInfo, err := info.Info()
if err != nil {
return nil, fmt.Errorf("failed to get file info for %s: %w", info.Name(), err)
}
buckets = append(buckets, Bucket{Name: unescaped, TimeCreated: timespecToTime(createTimeFromFileInfo(fileInfo))})
}
}
return buckets, nil
Expand Down