Files
firebase-ios-sdk/Example/Database/Tests/Integration/FDotInfo.m
T
Benoit St-Pierre 54659e8d99 Database Interop Rollforward (#2095)
* Register Database with Interop

+ Add AuthInterop dependency
+ Have Database register with Interop component container
+ Add weak dependency on Auth
~ Cleaned up imports

* Use Interop for Auth token fetching

+ Use macro to get auth component
~ Change `getTokenForcingRefresh:withCallback:` call to use Interop component version of Auth
~ Clean up imports

* Implement necessary protocols

+ Added FIRComponentRegistrant and FIRDatabaseNilProtocol to FIRDatabase

* Squash of my previous local commits for Database Interop

Register Database with Interop:

  + Add AuthInterop dependency
  + Have Database register with Interop component container
  + Add weak dependency on Auth
  ~ Cleaned up imports

Use Interop for Auth token fetching:

  + Use macro to get auth component
  ~ Change `getTokenForcingRefresh:withCallback:` call to use Interop component version of Auth
  ~ Clean up imports

Implement necessary protocols:

  + Added FIRComponentRegistrant and FIRDatabaseNilProtocol to FIRDatabase

Clean up Database tests:

  - Removed all unnecessary header files
  ~ Ran style.sh across all the tests

Cleaned Up project file:

  Some header removals were missed in the last commit.

Sorted some test files

Fix Database Fake App Tests:

  + Added container property
  + Added an Auth fake in the container
  + Added the Shared utils files to the necessary targets
  + Added a missing XCTest reference in a test that didn't compile for me

* Revert "Squash of my previous local commits for Database Interop"

This reverts commit c0d0421237.

* Cleaned Up project file

Some header removals were missed in the last commit.

* Sorted some test files

* Fix Database Fake App Tests

+ Added container property
+ Added an Auth fake in the container
+ Added the Shared utils files to the necessary targets
+ Added a missing XCTest reference in a test that didn't compile for me

* PR Feedback Changes

+ Created new FIRDatabaseComponent class to encapsulate instance creation
+ Updated FAuthTokenProvider to only use an auth instance rather than an app.

* PR Feedback Follow-Up

- Removed FIRDatabase registration code

* pod deintegrate

* Move instance management

Somes tests may still be out of date.

* Fix Auth integration test

* pod deintegrate -- again

* PR Feedback

* PR Feedback

Added the FIRComponentLifecycleMaintainer protocol to FIRDatabaseComponent

* Update Firebase/Database/Api/FIRDatabaseComponent.m

Missed some small changes

* Get integration tests compiling

* Fix some tests

* Fixed more tests

Component needs to be cacheable in order to get the appWIllBeDeleted callback.

* Update target memberships

* Revert project file changes

* Add FIRAuthInteropFake for broken targets

* PR feedback

* Spacing and Style

* Moved `instances` to ivar

* Simplify FIRDatabaseDictionary

It's now keyed on the URL with the app being implied since each app will get its own `FIRDatabaseComponent`

* Fix Database Integration Tests

Have the FakeApp cache DB instances
Use the Full host/URL path to cache DB instances
Simplified shared scheme

```
Test Suite 'Database_IntegrationTests_iOS.xctest' passed at 2018-11-20 07:09:30.520.
	 Executed 326 tests, with 0 failures (0 unexpected) in 66.251 (66.528) seconds
Test Suite 'All tests' passed at 2018-11-20 07:09:30.522.
	 Executed 326 tests, with 0 failures (0 unexpected) in 66.251 (66.530) seconds
```

* Clarify defaultApp use
2018-11-22 06:44:42 -05:00

174 lines
6.6 KiB
Objective-C

/*
* 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 "FDotInfo.h"
#import "FTestHelpers.h"
#import "FIRDatabaseConfig_Private.h"
@implementation FDotInfo
- (void) testCanGetReferenceToInfoNodes {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
[ref.root child:@".info"];
[ref.root child:@".info/foo"];
}
- (void) testCantWriteToInfo {
FIRDatabaseReference * ref = [[FTestHelpers getRandomNode].root child:@".info"];
XCTAssertThrows([ref setValue:@"hi"], @"Cannot write to path at /.info");
XCTAssertThrows([ref setValue:@"hi" andPriority:@5], @"Cannot write to path at /.info");
XCTAssertThrows([ref setPriority:@"hi"], @"Cannot write to path at /.info");
XCTAssertThrows([ref runTransactionBlock:^FIRTransactionResult *(FIRMutableData *currentData) {
return [FIRTransactionResult successWithValue:currentData];
}], @"Cannot write to path at /.info");
XCTAssertThrows([ref removeValue], @"Cannot write to path at /.info");
XCTAssertThrows([[ref child:@"test"] setValue:@"hi"], @"Cannot write to path at /.info");
}
- (void) testCanWatchInfoConnected {
FIRDatabaseReference * rootRef = [FTestHelpers getRandomNode].root;
__block BOOL done = NO;
[[rootRef child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
if ([[snapshot value] boolValue]) {
done = YES;
}
}];
[self waitUntil:^{ return done; }];
}
- (void) testInfoConnectedGoesToFalseOnDisconnect {
FIRDatabaseConfig *cfg = [FTestHelpers configForName:@"test-config"];
FIRDatabaseReference * rootRef = [[FIRDatabaseReference alloc] initWithConfig:cfg];
__block BOOL everConnected = NO;
__block NSMutableString *connectedHistory = [[NSMutableString alloc] init];
[[rootRef child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
if ([[snapshot value] boolValue]) {
everConnected = YES;
}
if (everConnected) {
[connectedHistory appendString:([[snapshot value] boolValue] ? @"YES," : @"NO,")];
}
}];
[self waitUntil:^{ return everConnected; }];
[FRepoManager interrupt:cfg];
[FRepoManager resume:cfg];
[self waitUntil:^BOOL{
return [connectedHistory isEqualToString:@"YES,NO,YES,"];
}];
[FRepoManager interrupt:cfg];
[FRepoManager disposeRepos:cfg];
}
- (void) testInfoServerTimeOffset {
FIRDatabaseConfig *cfg = [FTestHelpers configForName:@"test-config"];
FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:cfg];
// make sure childByAutoId works
[ref childByAutoId];
NSMutableArray* offsets = [[NSMutableArray alloc] init];
[[ref child:@".info/serverTimeOffset"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
NSLog(@"got value: %@", snapshot.value);
[offsets addObject:snapshot.value];
}];
WAIT_FOR(offsets.count == 1);
XCTAssertTrue([[offsets objectAtIndex:0] isKindOfClass:[NSNumber class]], @"Second element should be a number, in milliseconds");
// make sure childByAutoId still works
[ref childByAutoId];
[FRepoManager interrupt:cfg];
[FRepoManager disposeRepos:cfg];
}
- (void) testManualConnectionManagement {
FIRDatabaseConfig *cfg = [FTestHelpers configForName:@"test-config"];
FIRDatabaseConfig *altCfg = [FTestHelpers configForName:@"alt-config"];
FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:cfg];
FIRDatabaseReference * refAlt = [[FIRDatabaseReference alloc] initWithConfig:altCfg];
// Wait until we're connected to both Firebases
__block BOOL ready = NO;
[[ref child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
ready = [[snapshot value] boolValue];
}];
[self waitUntil:^{ return ready; }];
[[ref child:@".info/connected"] removeAllObservers];
ready = NO;
[[refAlt child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
ready = [[snapshot value] boolValue];
}];
[self waitUntil:^{ return ready; }];
[[refAlt child:@".info/connected"] removeAllObservers];
[FIRDatabaseReference goOffline];
// Ensure we're disconnected from both Firebases
ready = NO;
[[ref child:@".info/connected"] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertFalse([[snapshot value] boolValue], @".info/connected should be false");
ready = YES;
}];
[self waitUntil:^{ return ready; }];
ready = NO;
[[refAlt child:@".info/connected"] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
XCTAssertFalse([[snapshot value] boolValue], @".info/connected should be false");
ready = YES;
}];
[self waitUntil:^{ return ready; }];
// Ensure that we don't automatically reconnect upon new Firebase creation
FIRDatabaseReference * refDup = [[FIRDatabaseReference alloc] initWithConfig:altCfg];
[[refDup child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
if ([[snapshot value] boolValue]) {
XCTFail(@".info/connected should remain false");
}
}];
// Wait for 1.5 seconds to make sure connected remains false
[NSThread sleepForTimeInterval:1.5];
[[refDup child:@".info/connected"] removeAllObservers];
[FIRDatabaseReference goOnline];
// Ensure we're reconnected to both Firebases
ready = NO;
[[ref child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
ready = [[snapshot value] boolValue];
}];
[self waitUntil:^{ return ready; }];
[[ref child:@".info/connected"] removeAllObservers];
ready = NO;
[[refAlt child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
ready = [[snapshot value] boolValue];
}];
[self waitUntil:^{ return ready; }];
[[refAlt child:@".info/connected"] removeAllObservers];
}
@end