Skip to content

Adding tests to verify cloud patterns #107

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

Merged
merged 1 commit into from
Jun 24, 2025
Merged
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
23 changes: 21 additions & 2 deletions test/tZarrCreate.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
% Copyright 2025 The MathWorks, Inc.

methods(Test)

function createDefaultArray(testcase)
% Verify that zarrcreate correctly creates a Zarr array with
% all default properties
Expand All @@ -25,7 +24,6 @@ function createDefaultArray(testcase)
actInfo = zarrinfo(testcase.ArrPathWrite);
testcase.verifyEqual(actInfo, expInfo,...
'Failed to verify creating Zarr array with default properties');

end

function createIntermediateZgroups(testcase)
Expand Down Expand Up @@ -64,6 +62,27 @@ function createArrayRelativePath(testcase)
testcase.verifyEqual(arrInfo.node_type,'array','Unexpected Zarr array node type');
end

function verifySupportedCloudPatterns(testcase)
% Verify that the bucket name and the array path can be
% extracted successfully if a cloud path is used as an input.

% This list contains path pattern currently supported by Zarr
% in MATLAB. Any invalid path not matching any of these
% patterns will result in an error.
inpPath = {'https://mybucket.s3.us-west-2.amazonaws.com/path/to/myZarrFile', ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious - why cell array of char vectors instead of a more modern array of strings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing specific.

'https://mybucket.s3.amazonaws.com/path/to/myZarrFile', ...
'https://mybucket.s3.custom-endpoint.org/path/to/myZarrFile', ...
'https://s3.amazonaws.com/mybucket/path/to/myZarrFile', ...
'https://s3.eu-central-1.example.edu/mybucket/path/to/myZarrFile', ...
's3://mybucket/path/to/myZarrFile'};

for i = 1:length(inpPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor and somewhat subjective, but you can use a for-each loop if you don't need the index i for anything else other than getting the current path

paths = ["path1", "path2", "path3"]; % has to be a row vector
for p = paths % iterate over the array of strings directly instead of using index
disp(p)
end

That way you don't have to keep doing {i} to access the current path. Alternatively, can save the current path to a separate variable first currPath = inpPath{i}.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but keeping it as is for now, for better readability.

[bucketName, objectPath] = Zarr.extractS3BucketNameAndPath(inpPath{i});
testcase.verifyEqual(bucketName, 'mybucket', ['Bucket name extraction failed for ' inpPath{i}]);
testcase.verifyEqual(objectPath, 'path/to/myZarrFile', ['Object path extraction failed for ' inpPath{i}]);
end
end

function invalidFilePath(testcase)
% Verify error when an invalid file path is used as an input to
% zarrcreate function.
Expand Down