| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- // Copyright 2017 Google
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #import "FirebaseStorage.h"
- #import "FIRComponentTestUtilities.h"
- #import "FIRStorageComponent.h"
- #import "FIRStorageReference_Private.h"
- #import "FIRStorageTestHelpers.h"
- @interface FIRStorageReferenceTests : XCTestCase
- @property(strong, nonatomic) FIRStorage *storage;
- @end
- @implementation FIRStorageReferenceTests
- - (void)setUp {
- [super setUp];
- id mockOptions = OCMClassMock([FIROptions class]);
- OCMStub([mockOptions storageBucket]).andReturn(@"bucket");
- id mockApp = [FIRStorageTestHelpers mockedApp];
- OCMStub([mockApp name]).andReturn(kFIRStorageAppName);
- OCMStub([(FIRApp *)mockApp options]).andReturn(mockOptions);
- self.storage = [FIRStorage storageForApp:mockApp];
- }
- - (void)tearDown {
- self.storage = nil;
- [super tearDown];
- }
- - (void)testRoot {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/path/to/object"];
- XCTAssertEqualObjects([ref.root stringValue], @"gs://bucket/");
- }
- - (void)testRootWithNoPath {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- XCTAssertEqualObjects([ref.root stringValue], @"gs://bucket/");
- }
- - (void)testSingleChild {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- FIRStorageReference *childRef = [ref child:@"path"];
- XCTAssertEqualObjects([childRef stringValue], @"gs://bucket/path");
- }
- - (void)testMultipleChildrenSingleString {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- FIRStorageReference *childRef = [ref child:@"path/to/object"];
- XCTAssertEqualObjects([childRef stringValue], @"gs://bucket/path/to/object");
- }
- - (void)testMultipleChildrenMultipleStrings {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- FIRStorageReference *childRef = [ref child:@"path"];
- childRef = [childRef child:@"to"];
- childRef = [childRef child:@"object"];
- XCTAssertEqualObjects([childRef stringValue], @"gs://bucket/path/to/object");
- }
- - (void)testSameChildDifferentRef {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- FIRStorageReference *firstRef = [ref child:@"1"];
- FIRStorageReference *secondRef = [ref child:@"1"];
- XCTAssertEqualObjects([ref stringValue], @"gs://bucket/");
- XCTAssertEqualObjects(firstRef, secondRef);
- XCTAssertNotEqual(firstRef, secondRef);
- }
- - (void)testDifferentChildDifferentRef {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- FIRStorageReference *firstRef = [ref child:@"1"];
- FIRStorageReference *secondRef = [ref child:@"2"];
- XCTAssertEqualObjects([ref stringValue], @"gs://bucket/");
- XCTAssertNotEqual(firstRef, secondRef);
- }
- - (void)testChildWithTrailingSlash {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/path/to/object/"];
- XCTAssertEqualObjects([ref stringValue], @"gs://bucket/path/to/object");
- }
- - (void)testChildWithLeadingSlash {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket//path/to/object/"];
- XCTAssertEqualObjects([ref stringValue], @"gs://bucket/path/to/object");
- }
- - (void)testChildCompressSlashes {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket//path///to////object////"];
- XCTAssertEqualObjects([ref stringValue], @"gs://bucket/path/to/object");
- }
- - (void)testParent {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/path/to/object"];
- FIRStorageReference *parentRef = [ref parent];
- XCTAssertEqualObjects([parentRef stringValue], @"gs://bucket/path/to");
- }
- - (void)testParentToRoot {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/path"];
- FIRStorageReference *parentRef = [ref parent];
- XCTAssertEqualObjects([parentRef stringValue], @"gs://bucket/");
- }
- - (void)testParentToRootTrailingSlash {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/path/"];
- FIRStorageReference *parentRef = [ref parent];
- XCTAssertEqualObjects([parentRef stringValue], @"gs://bucket/");
- }
- - (void)testParentAtRoot {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- FIRStorageReference *parentRef = [ref parent];
- XCTAssertNil(parentRef);
- }
- - (void)testBucket {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/path/to/object"];
- XCTAssertEqualObjects(ref.bucket, @"bucket");
- }
- - (void)testName {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/path/to/object"];
- XCTAssertEqualObjects(ref.name, @"object");
- }
- - (void)testNameNoObject {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- XCTAssertEqualObjects(ref.name, @"");
- }
- - (void)testFullPath {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/path/to/object"];
- XCTAssertEqualObjects(ref.fullPath, @"path/to/object");
- }
- - (void)testFullPathNoObject {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- XCTAssertEqualObjects(ref.fullPath, @"");
- }
- - (void)testCopy {
- FIRStorageReference *ref = [self.storage referenceForURL:@"gs://bucket/"];
- FIRStorageReference *copiedRef = [ref copy];
- XCTAssertEqualObjects(ref, copiedRef);
- XCTAssertNotEqual(ref, copiedRef);
- }
- - (void)testReferenceWithNonExistentFileFailsWithCompletion {
- NSString *tempFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"temp.data"];
- FIRStorageReference *ref = [self.storage referenceWithPath:tempFilePath];
- NSURL *dummyFileURL = [NSURL fileURLWithPath:@"some_non_existing-folder/file.data"];
- XCTestExpectation *expectation = [self expectationWithDescription:@"completionExpectation"];
- [ref putFile:dummyFileURL
- metadata:nil
- completion:^(FIRStorageMetadata *_Nullable metadata, NSError *_Nullable error) {
- [expectation fulfill];
- XCTAssertNotNil(error);
- XCTAssertNil(metadata);
- XCTAssertEqualObjects(error.domain, FIRStorageErrorDomain);
- XCTAssertEqual(error.code, FIRStorageErrorCodeUnknown);
- NSString *expectedDescription = [NSString
- stringWithFormat:@"File at URL: %@ is not reachable.", dummyFileURL.absoluteString];
- XCTAssertEqualObjects(error.localizedDescription, expectedDescription);
- }];
- [self waitForExpectationsWithTimeout:0.5 handler:NULL];
- }
- - (void)testReferenceWithNilFileURLFailsWithCompletion {
- NSString *tempFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"temp.data"];
- FIRStorageReference *ref = [self.storage referenceWithPath:tempFilePath];
- NSURL *dummyFileURL = nil;
- XCTestExpectation *expectation = [self expectationWithDescription:@"completionExpectation"];
- [ref putFile:dummyFileURL
- metadata:nil
- completion:^(FIRStorageMetadata *_Nullable metadata, NSError *_Nullable error) {
- [expectation fulfill];
- XCTAssertNotNil(error);
- XCTAssertNil(metadata);
- XCTAssertEqualObjects(error.domain, FIRStorageErrorDomain);
- XCTAssertEqual(error.code, FIRStorageErrorCodeUnknown);
- NSString *expectedDescription = @"File at URL: (null) is not reachable.";
- XCTAssertEqualObjects(error.localizedDescription, expectedDescription);
- }];
- [self waitForExpectationsWithTimeout:0.5 handler:NULL];
- }
- @end
|