From e942f3c339f0eb617ac4dbc7f37cc4e5920ee7cc Mon Sep 17 00:00:00 2001 From: Robert van Gent Date: Fri, 2 Dec 2022 14:28:20 -0800 Subject: [PATCH] blob/azblob: Restore As for List entry (#3188) --- blob/azureblob/azureblob.go | 8 ++++++-- blob/azureblob/azureblob_test.go | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/blob/azureblob/azureblob.go b/blob/azureblob/azureblob.go index bf9bb27f6b..b06e8ab621 100644 --- a/blob/azureblob/azureblob.go +++ b/blob/azureblob/azureblob.go @@ -77,7 +77,7 @@ // azureblob exposes the following types for As: // - Bucket: *container.Client // - Error: *azcore.ReponseError. You can use bloberror.HasCode directly though. -// - ListObject: N/A. +// - ListObject: container.BlobItem for objects, none for "directories" // - ListOptions.BeforeList: *container.ListBlobsHierarchyOptions // - Reader: azblobblob.DownloadStreamResponse // - Reader.BeforeRead: *azblob.DownloadStreamOptions @@ -754,7 +754,11 @@ func (b *bucket) ListPaged(ctx context.Context, opts *driver.ListOptions) (*driv MD5: blobInfo.Properties.ContentMD5, IsDir: false, AsFunc: func(i interface{}) bool { - return false + v, ok := i.(*container.BlobItem) + if ok { + *v = *blobInfo + } + return ok }, }) } diff --git a/blob/azureblob/azureblob_test.go b/blob/azureblob/azureblob_test.go index 11ded5c2b1..63ae3009dd 100644 --- a/blob/azureblob/azureblob_test.go +++ b/blob/azureblob/azureblob_test.go @@ -246,6 +246,16 @@ func (verifyContentLanguage) ReaderCheck(r *blob.Reader) error { } func (verifyContentLanguage) ListObjectCheck(o *blob.ListObject) error { + if o.IsDir { + return nil + } + var item container.BlobItem + if !o.As(&item) { + return errors.New("ListObject.As for object returned false") + } + if got := *item.Properties.ContentLanguage; got != language { + return fmt.Errorf("got %q want %q", got, language) + } return nil }