Skip to content

Commit 143caf9

Browse files
Storage: Add List API (#3176)
1 parent 407c2ac commit 143caf9

21 files changed

+942
-16
lines changed

Example/Firebase.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@
350350
D0FE8A941ED9CAAE003F6722 /* FIRAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D0FE8A1A1ED9C6D2003F6722 /* FIRAppDelegate.m */; };
351351
D0FE8A951ED9CAAE003F6722 /* FIRViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0FE8A1C1ED9C6D2003F6722 /* FIRViewController.m */; };
352352
D0FE8A961ED9CAAE003F6722 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D0FE8A1D1ED9C6D2003F6722 /* main.m */; };
353+
D5B2514347161203F929FA47 /* FIRStorageListTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B2545FC99E33265C65CAA4 /* FIRStorageListTests.m */; };
354+
D5B251C16CD531364AA90C58 /* FIRStorageListTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B2545FC99E33265C65CAA4 /* FIRStorageListTests.m */; };
355+
D5B253A8C57176FF8C368F4E /* FIRStorageListTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B2545FC99E33265C65CAA4 /* FIRStorageListTests.m */; };
353356
D9B0D41E1F578F6D00A567C2 /* FIRGetProjectConfigRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D92C82C61F578DF000D5EAFF /* FIRGetProjectConfigRequestTests.m */; };
354357
D9B0D41F1F578F6E00A567C2 /* FIRGetProjectConfigRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D92C82C61F578DF000D5EAFF /* FIRGetProjectConfigRequestTests.m */; };
355358
D9B0D4201F578F7200A567C2 /* FIRGetProjectConfigResponseTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D92C82C51F578DF000D5EAFF /* FIRGetProjectConfigResponseTests.m */; };
@@ -1187,6 +1190,7 @@
11871190
D0FE8A2F1ED9C804003F6722 /* Database_Example_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Database_Example_macOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
11881191
D0FE8A621ED9C870003F6722 /* Database_Tests_macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Database_Tests_macOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
11891192
D0FE8A8C1ED9C87B003F6722 /* Database_IntegrationTests_macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Database_IntegrationTests_macOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
1193+
D5B2545FC99E33265C65CAA4 /* FIRStorageListTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRStorageListTests.m; sourceTree = "<group>"; };
11901194
D92C82C51F578DF000D5EAFF /* FIRGetProjectConfigResponseTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRGetProjectConfigResponseTests.m; sourceTree = "<group>"; };
11911195
D92C82C61F578DF000D5EAFF /* FIRGetProjectConfigRequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRGetProjectConfigRequestTests.m; sourceTree = "<group>"; };
11921196
DE0E5BB51EA7D91C00FAA825 /* FIRAuthAppCredentialTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRAuthAppCredentialTests.m; sourceTree = "<group>"; };
@@ -1883,6 +1887,7 @@
18831887
DEB139C91E734D9D00AC236D /* FIRStorageTokenAuthorizerTests.m */,
18841888
DEB139CA1E734D9D00AC236D /* FIRStorageUpdateMetadataTests.m */,
18851889
DEB139CB1E734D9D00AC236D /* FIRStorageUtilsTests.m */,
1890+
D5B2545FC99E33265C65CAA4 /* FIRStorageListTests.m */,
18861891
);
18871892
path = Unit;
18881893
sourceTree = "<group>";
@@ -4603,6 +4608,7 @@
46034608
D0EDB2EA1EDA06CB00B6C31B /* FIRStorageTokenAuthorizerTests.m in Sources */,
46044609
D0EDB2EB1EDA06CB00B6C31B /* FIRStorageReferenceTests.m in Sources */,
46054610
D0EDB2EC1EDA06CB00B6C31B /* FIRStoragePathTests.m in Sources */,
4611+
D5B251C16CD531364AA90C58 /* FIRStorageListTests.m in Sources */,
46064612
);
46074613
runOnlyForDeploymentPostprocessing = 0;
46084614
};
@@ -5164,6 +5170,7 @@
51645170
DEAAD4271FBA49ED0053BF48 /* FIRStorageTestHelpers.m in Sources */,
51655171
DEAAD4281FBA49ED0053BF48 /* FIRStorageTests.m in Sources */,
51665172
DEAAD4241FBA49ED0053BF48 /* FIRStorageMetadataTests.m in Sources */,
5173+
D5B253A8C57176FF8C368F4E /* FIRStorageListTests.m in Sources */,
51675174
);
51685175
runOnlyForDeploymentPostprocessing = 0;
51695176
};
@@ -5194,6 +5201,7 @@
51945201
DEB13A2E1E73518B00AC236D /* FIRStorageTokenAuthorizerTests.m in Sources */,
51955202
DEB13A2B1E73518B00AC236D /* FIRStorageReferenceTests.m in Sources */,
51965203
DEB13A2A1E73518B00AC236D /* FIRStoragePathTests.m in Sources */,
5204+
D5B2514347161203F929FA47 /* FIRStorageListTests.m in Sources */,
51975205
);
51985206
runOnlyForDeploymentPostprocessing = 0;
51995207
};

Example/Firebase.xcodeproj/xcshareddata/xcschemes/InstanceID_Tests_iOS.xcscheme

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForRunning = "YES"
11+
buildForTesting = "YES">
12+
<BuildableReference
13+
BuildableIdentifier = "primary"
14+
BlueprintIdentifier = "DE958B7421F7D15900E6C1C5"
15+
BuildableName = "InstanceID_Tests_iOS.xctest"
16+
BlueprintName = "InstanceID_Tests_iOS"
17+
ReferencedContainer = "container:Firebase.xcodeproj">
18+
</BuildableReference>
19+
</BuildActionEntry>
20+
</BuildActionEntries>
821
</BuildAction>
922
<TestAction
1023
buildConfiguration = "Debug"

Example/Firebase.xcodeproj/xcshareddata/xcschemes/InstanceID_Tests_tvOS.xcscheme

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForRunning = "YES"
11+
buildForTesting = "YES">
12+
<BuildableReference
13+
BuildableIdentifier = "primary"
14+
BlueprintIdentifier = "518854EB223066BE00CA4141"
15+
BuildableName = "InstanceID_Tests_tvOS.xctest"
16+
BlueprintName = "InstanceID_Tests_tvOS"
17+
ReferencedContainer = "container:Firebase.xcodeproj">
18+
</BuildableReference>
19+
</BuildActionEntry>
20+
</BuildActionEntries>
821
</BuildAction>
922
<TestAction
1023
buildConfiguration = "Debug"

Example/Firebase.xcodeproj/xcshareddata/xcschemes/Messaging_Tests_tvOS.xcscheme

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForRunning = "YES"
11+
buildForTesting = "YES">
12+
<BuildableReference
13+
BuildableIdentifier = "primary"
14+
BlueprintIdentifier = "511DD2872225C5A80094D78D"
15+
BuildableName = "Messaging_Tests_tvOS.xctest"
16+
BlueprintName = "Messaging_Tests_tvOS"
17+
ReferencedContainer = "container:Firebase.xcodeproj">
18+
</BuildableReference>
19+
</BuildActionEntry>
20+
</BuildActionEntries>
821
</BuildAction>
922
<TestAction
1023
buildConfiguration = "Debug"

Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*
3030
* A sample configuration may look like:
3131
*
32+
* rules_version = '2';
3233
* service firebase.storage {
3334
* match /b/{bucket}/o {
3435
* ...
@@ -66,9 +67,13 @@ - (void)setUp {
6667

6768
static dispatch_once_t once;
6869
dispatch_once(&once, ^{
69-
XCTestExpectation *expectation = [self expectationWithDescription:@"setup"];
70+
XCTestExpectation *setUpExpectation = [self expectationWithDescription:@"setUp"];
7071

71-
FIRStorageReference *ref = [[FIRStorage storage].reference child:@"ios/public/1mb"];
72+
NSArray<NSString *> *largeFiles = @[ @"ios/public/1mb" ];
73+
NSArray<NSString *> *emptyFiles = @[
74+
@"ios/public/empty", @"ios/public/list/a", @"ios/public/list/b", @"ios/public/list/prefix/c"
75+
];
76+
setUpExpectation.expectedFulfillmentCount = largeFiles.count + emptyFiles.count;
7277

7378
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"1mb" ofType:@"dat"];
7479
if (filePath == nil) {
@@ -77,14 +82,27 @@ - (void)setUp {
7782
filePath = [bundle pathForResource:@"1mb" ofType:@"dat"];
7883
}
7984
NSData *data = [NSData dataWithContentsOfFile:filePath];
80-
8185
XCTAssertNotNil(data, "Could not load bundled file");
82-
[ref putData:data
83-
metadata:nil
84-
completion:^(FIRStorageMetadata *metadata, NSError *error) {
85-
XCTAssertNil(error);
86-
[expectation fulfill];
87-
}];
86+
87+
for (NSString *largeFile in largeFiles) {
88+
FIRStorageReference *file = [[FIRStorage storage].reference child:largeFile];
89+
[file putData:data
90+
metadata:nil
91+
completion:^(FIRStorageMetadata *metadata, NSError *error) {
92+
XCTAssertNil(error);
93+
[setUpExpectation fulfill];
94+
}];
95+
}
96+
97+
for (NSString *emptyFile in emptyFiles) {
98+
FIRStorageReference *file = [[FIRStorage storage].reference child:emptyFile];
99+
[file putData:[NSData data]
100+
metadata:nil
101+
completion:^(FIRStorageMetadata *metadata, NSError *error) {
102+
XCTAssertNil(error);
103+
[setUpExpectation fulfill];
104+
}];
105+
}
88106

89107
[self waitForExpectations];
90108
});
@@ -728,6 +746,59 @@ - (void)testUnauthenticatedResumeGetFileInBackgroundQueue {
728746
XCTAssertEqual(INT_MAX, resumeAtBytes);
729747
}
730748

749+
- (void)testPagedListFiles {
750+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPagedListFiles"];
751+
752+
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/list"];
753+
754+
[ref listWithMaxResults:2
755+
completion:^(FIRStorageListResult *_Nullable listResult, NSError *_Nullable error) {
756+
XCTAssertNotNil(listResult);
757+
XCTAssertNil(error);
758+
759+
XCTAssertEqualObjects(listResult.items, (@[ [ref child:@"a"], [ref child:@"b"] ]));
760+
XCTAssertEqualObjects(listResult.prefixes, @[]);
761+
XCTAssertNotNil(listResult.pageToken);
762+
763+
[ref listWithMaxResults:2
764+
pageToken:listResult.pageToken
765+
completion:^(FIRStorageListResult *_Nullable listResult,
766+
NSError *_Nullable error) {
767+
XCTAssertNotNil(listResult);
768+
XCTAssertNil(error);
769+
770+
XCTAssertEqualObjects(listResult.items, @[]);
771+
XCTAssertEqualObjects(listResult.prefixes,
772+
@[ [ref child:@"prefix"] ]);
773+
XCTAssertNil(listResult.pageToken);
774+
775+
[expectation fulfill];
776+
}];
777+
}];
778+
779+
[self waitForExpectations];
780+
}
781+
782+
- (void)testListAllFiles {
783+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPagedListFiles"];
784+
785+
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/list"];
786+
787+
[ref listAllWithCompletion:^(FIRStorageListResult *_Nullable listResult,
788+
NSError *_Nullable error) {
789+
XCTAssertNotNil(listResult);
790+
XCTAssertNil(error);
791+
792+
XCTAssertEqualObjects(listResult.items, (@[ [ref child:@"a"], [ref child:@"b"] ]));
793+
XCTAssertEqualObjects(listResult.prefixes, @[ [ref child:@"prefix"] ]);
794+
XCTAssertNil(listResult.pageToken);
795+
796+
[expectation fulfill];
797+
}];
798+
799+
[self waitForExpectations];
800+
}
801+
731802
- (void)waitForExpectations {
732803
[self waitForExpectationsWithTimeout:kFIRStorageIntegrationTestTimeout
733804
handler:^(NSError *_Nullable error) {

Example/Storage/Tests/Unit/FIRStorageDeleteTests.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ @interface FIRStorageDeleteTests : XCTestCase
1919

2020
@property(strong, nonatomic) GTMSessionFetcherService *fetcherService;
2121
@property(nonatomic) dispatch_queue_t dispatchQueue;
22-
@property(strong, nonatomic) FIRStorageMetadata *metadata;
2322
@property(strong, nonatomic) FIRStorage *storage;
2423
@property(strong, nonatomic) id mockApp;
2524

@@ -30,9 +29,6 @@ @implementation FIRStorageDeleteTests
3029
- (void)setUp {
3130
[super setUp];
3231

33-
NSDictionary *metadataDict = @{@"bucket" : @"bucket", @"name" : @"path/to/object"};
34-
self.metadata = [[FIRStorageMetadata alloc] initWithDictionary:metadataDict];
35-
3632
id mockOptions = OCMClassMock([FIROptions class]);
3733
OCMStub([mockOptions storageBucket]).andReturn(@"bucket.appspot.com");
3834

@@ -59,7 +55,7 @@ - (void)tearDown {
5955
}
6056

6157
- (void)testFetcherConfiguration {
62-
XCTestExpectation *expectation = [self expectationWithDescription:@"testSuccessfulFetch"];
58+
XCTestExpectation *expectation = [self expectationWithDescription:@"testFetcherConfiguration"];
6359

6460
self.fetcherService.testBlock =
6561
^(GTMSessionFetcher *fetcher, GTMSessionFetcherTestResponse response) {

0 commit comments

Comments
 (0)