-
Notifications
You must be signed in to change notification settings - Fork 0
feat(Storage): Add filter to ListObjectOptions and integration tests for object context #11
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,15 @@ | |
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using Google.Apis.Storage.v1.Data; | ||
| using Google.Cloud.ClientTesting; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
| using static Google.Cloud.Storage.V1.IntegrationTests.TestHelpers; | ||
|
|
||
| namespace Google.Cloud.Storage.V1.IntegrationTests | ||
| { | ||
|
|
@@ -87,5 +91,37 @@ public async Task GetSoftDeleted() | |
| Assert.Equal((ulong) _fixture.SmallContent.Length, softDeleted.Size); | ||
| Assert.NotNull(softDeleted.SoftDeleteTimeDateTimeOffset); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetObjectContexts() | ||
| { | ||
| string contextKey = "A\u00F1\u03A9\U0001F680"; | ||
| string contextValue = "Ab\u00F1\u03A9\U0001F680"; | ||
| var custom = new Dictionary<string, ObjectCustomContextPayload> | ||
| { | ||
| { contextKey, new ObjectCustomContextPayload { Value = contextValue } } | ||
| }; | ||
|
|
||
| var destination = new Object | ||
| { | ||
| Bucket = _fixture.MultiVersionBucket, | ||
| Name = IdGenerator.FromGuid(), | ||
| ContentType = "test/type", | ||
| ContentDisposition = "attachment", | ||
| Metadata = new Dictionary<string, string> { { "x", "y" } }, | ||
| Contexts = new Object.ContextsData { Custom = custom } | ||
| }; | ||
| var source = GenerateData(100); | ||
| var result = _fixture.Client.UploadObject(destination, source); | ||
|
|
||
|
|
||
| var obj = _fixture.Client.GetObject(_fixture.MultiVersionBucket, destination.Name); | ||
| Assert.Equal(_fixture.MultiVersionBucket, obj.Bucket); | ||
| Assert.NotNull(obj.Contexts); | ||
| Assert.Equal(obj.Contexts.Custom.Count, result.Contexts.Custom.Count); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current assertion only checks if the number of custom context entries is the same. This is a weak assertion as it doesn't verify the actual content (keys and values). A more robust test would compare the fetched context with the original data to ensure they are identical. Assert.Equal(custom, obj.Contexts.Custom); |
||
| var resultEntry = Assert.Single(obj.Contexts.Custom); | ||
| Assert.Equal(contextKey, resultEntry.Key); | ||
| Assert.Equal(contextValue, resultEntry.Value.Value); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ public void ModifyRequest_DefaultOptions() | |
| Assert.Null(request.StartOffset); | ||
| Assert.Null(request.EndOffset); | ||
| Assert.Null(request.MatchGlob); | ||
| Assert.Null(request.Filter); | ||
| } | ||
|
|
||
| [Fact] | ||
|
|
@@ -58,7 +59,8 @@ public void ModifyRequest_AllOptions() | |
| Fields = "items(name),nextPageToken", | ||
| StartOffset = "start", | ||
| EndOffset = "end", | ||
| MatchGlob = "a/*.txt" | ||
| MatchGlob = "a/*.txt", | ||
| Filter = "contexts.\"key\":*\"" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }; | ||
| options.ModifyRequest(request); | ||
| Assert.Equal(10, request.MaxResults); | ||
|
|
@@ -74,6 +76,7 @@ public void ModifyRequest_AllOptions() | |
| Assert.Equal("start", request.StartOffset); | ||
| Assert.Equal("end", request.EndOffset); | ||
| Assert.Equal("a/*.txt", request.MatchGlob); | ||
| Assert.Equal("contexts.\"key\":*\"", request.Filter); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current assertion only checks the count of custom contexts. To ensure the object context was correctly retrieved, you should also assert that the actual key-value pairs within
obj.Contexts.Custommatch those inresult.Contexts.Custom. This provides a more comprehensive validation of the retrieved context data.