14
14
* limitations under the License.
15
15
*/
16
16
17
- // Uncomment to enable integration tests.
18
- // #define FIR_INSTALLATIONS_INTEGRATION_TESTS_ENABLED 1
19
-
20
- #ifdef FIR_INSTALLATIONS_INTEGRATION_TESTS_ENABLED
17
+ // Uncomment or set the flag in GCC_PREPROCESSOR_DEFINITIONS to enable integration tests.
18
+ // #define FIR_INSTALLATIONS_INTEGRATION_TESTS_REQUIRED 1
21
19
22
20
#import < XCTest/XCTest.h>
23
21
31
29
#import < FirebaseInstallations/FIRInstallations.h>
32
30
#import < FirebaseInstallations/FIRInstallationsAuthTokenResult.h>
33
31
32
+ static BOOL sFIRInstallationsFirebaseDefaultAppConfigured = NO ;
33
+
34
34
@interface FIRInstallationsIntegrationTests : XCTestCase
35
35
@property (nonatomic ) FIRInstallations *installations;
36
36
@end
37
37
38
38
@implementation FIRInstallationsIntegrationTests
39
39
40
40
- (void )setUp {
41
- static dispatch_once_t onceToken;
42
- dispatch_once (&onceToken, ^{
43
- [FIRApp configure ];
44
- });
41
+ [self configureFirebaseDefaultAppIfCan ];
42
+
43
+ if (![self isDefaultAppConfigured ]) {
44
+ return ;
45
+ }
45
46
46
47
self.installations = [FIRInstallations installationsWithApp: [FIRApp defaultApp ]];
47
48
}
@@ -54,19 +55,29 @@ - (void)tearDown {
54
55
55
56
// Wait for any pending background job to be completed.
56
57
FBLWaitForPromisesWithTimeout (10 );
58
+
59
+ [FIRApp resetApps ];
57
60
}
58
61
59
62
// TODO: Enable the test once Travis configured.
60
63
// Need to configure the GoogleService-Info.plist copying from the encrypted archive.
61
64
// So far, let's run the tests locally.
62
- - (void )disabled_testGetFID {
65
+ - (void )testGetFID {
66
+ if (![self isDefaultAppConfigured ]) {
67
+ return ;
68
+ }
69
+
63
70
NSString *FID1 = [self getFID ];
64
71
NSString *FID2 = [self getFID ];
65
72
66
73
XCTAssertEqualObjects (FID1, FID2);
67
74
}
68
75
69
- - (void )disabled_testAuthToken {
76
+ - (void )testAuthToken {
77
+ if (![self isDefaultAppConfigured ]) {
78
+ return ;
79
+ }
80
+
70
81
XCTestExpectation *authTokenExpectation =
71
82
[self expectationWithDescription: @" authTokenExpectation" ];
72
83
@@ -84,7 +95,11 @@ - (void)disabled_testAuthToken {
84
95
[self waitForExpectations: @[ authTokenExpectation ] timeout: 2 ];
85
96
}
86
97
87
- - (void )disabled_testDeleteInstallation {
98
+ - (void )testDeleteInstallation {
99
+ if (![self isDefaultAppConfigured ]) {
100
+ return ;
101
+ }
102
+
88
103
NSString *FIDBefore = [self getFID ];
89
104
FIRInstallationsAuthTokenResult *authTokenBefore = [self getAuthToken ];
90
105
@@ -111,20 +126,20 @@ - (void)testInstallationsWithApp {
111
126
112
127
// Wait for finishing all background operations.
113
128
FBLWaitForPromisesWithTimeout (10 );
114
-
115
- [FIRApp resetApps ];
116
129
}
117
130
118
131
- (void )testDefaultAppInstallation {
132
+ if (![self isDefaultAppConfigured ]) {
133
+ return ;
134
+ }
135
+
119
136
XCTAssertNotNil (self.installations );
120
137
XCTAssertEqualObjects (self.installations .appOptions .googleAppID ,
121
138
[FIRApp defaultApp ].options .googleAppID );
122
139
XCTAssertEqualObjects (self.installations .appName , [FIRApp defaultApp ].name );
123
140
124
141
// Wait for finishing all background operations.
125
142
FBLWaitForPromisesWithTimeout (10 );
126
-
127
- [FIRApp resetApps ];
128
143
}
129
144
130
145
#endif // !TARGET_OS_OSX
@@ -197,6 +212,30 @@ - (FIRApp *)createAndConfigureAppWithName:(NSString *)name {
197
212
return [FIRApp appNamed: name];
198
213
}
199
214
200
- @end
215
+ - (void )configureFirebaseDefaultAppIfCan {
216
+ NSBundle *bundle = [NSBundle bundleForClass: [self class ]];
217
+ NSString *plistPath = [bundle pathForResource: @" GoogleService-Info" ofType: @" plist" ];
218
+ if (plistPath == nil ) {
219
+ return ;
220
+ }
201
221
202
- #endif // FIR_INSTALLATIONS_INTEGRATION_TESTS_ENABLED
222
+ FIROptions *options = [[FIROptions alloc ] initWithContentsOfFile: plistPath];
223
+ [FIRApp configureWithOptions: options];
224
+ sFIRInstallationsFirebaseDefaultAppConfigured = YES ;
225
+ }
226
+
227
+ - (BOOL )isDefaultAppConfigured {
228
+ if (!sFIRInstallationsFirebaseDefaultAppConfigured ) {
229
+ #if FIR_INSTALLATIONS_INTEGRATION_TESTS_REQUIRED
230
+ XCTFail (@" GoogleService-Info.plist for integration tests was not found. Please add the file to "
231
+ @" your project." );
232
+ #else
233
+ NSLog (@" GoogleService-Info.plist for integration tests was not found. Skipping the test %@ " ,
234
+ self.name );
235
+ #endif // FIR_INSTALLATIONS_INTEGRATION_TESTS_REQUIRED
236
+ }
237
+
238
+ return sFIRInstallationsFirebaseDefaultAppConfigured ;
239
+ }
240
+
241
+ @end
0 commit comments