Skip to content

Commit 89bae97

Browse files
Firebase Installations: integration tests on Travis (#3652)
1 parent e451960 commit 89bae97

File tree

7 files changed

+75
-46
lines changed

7 files changed

+75
-46
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Example/Database/App/GoogleService-Info.plist
99

1010
Example/Storage/App/GoogleService-Info.plist
1111

12+
# FirebaseInstallations integration tests GoogleService-Info.plist
13+
FirebaseInstallations/Source/Tests/Resources/GoogleService-Info.plist
14+
1215
Secrets.tar
1316

1417
# OS X

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ jobs:
420420
- stage: test
421421
env:
422422
- PROJECT=Installations PLATFORM=iOS METHOD=pod-lib-lint
423+
before_install:
424+
- ./scripts/if_changed.sh ./scripts/install_prereqs.sh
423425
script:
424426
- travis_retry ./scripts/if_changed.sh ./scripts/pod_lib_lint.rb FirebaseInstallations.podspec --platforms=ios,tvos --ignore-local-podspecs=FirebaseInstanceID.podspec
425427
# TODO: Fix FBLPromises warnings for macOS.

FirebaseInstallations.podspec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ Pod::Spec.new do |s|
4949
s.test_spec 'integration' do |int_tests|
5050
int_tests.source_files = base_dir + 'Tests/Integration/**/*.[mh]'
5151
int_tests.resources = base_dir + 'Tests/Resources/**/*'
52+
s.pod_target_xcconfig = {
53+
'GCC_PREPROCESSOR_DEFINITIONS' =>
54+
'FIR_INSTALLATIONS_INTEGRATION_TESTS_REQUIRED=1'
55+
}
5256
int_tests.requires_app_host = true
5357
int_tests.dependency 'OCMock'
5458
end

FirebaseInstallations/Source/Tests/Integration/FIRInstallationsIntegrationTests.m

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

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
2119

2220
#import <XCTest/XCTest.h>
2321

@@ -31,17 +29,20 @@
3129
#import <FirebaseInstallations/FIRInstallations.h>
3230
#import <FirebaseInstallations/FIRInstallationsAuthTokenResult.h>
3331

32+
static BOOL sFIRInstallationsFirebaseDefaultAppConfigured = NO;
33+
3434
@interface FIRInstallationsIntegrationTests : XCTestCase
3535
@property(nonatomic) FIRInstallations *installations;
3636
@end
3737

3838
@implementation FIRInstallationsIntegrationTests
3939

4040
- (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+
}
4546

4647
self.installations = [FIRInstallations installationsWithApp:[FIRApp defaultApp]];
4748
}
@@ -54,19 +55,29 @@ - (void)tearDown {
5455

5556
// Wait for any pending background job to be completed.
5657
FBLWaitForPromisesWithTimeout(10);
58+
59+
[FIRApp resetApps];
5760
}
5861

5962
// TODO: Enable the test once Travis configured.
6063
// Need to configure the GoogleService-Info.plist copying from the encrypted archive.
6164
// So far, let's run the tests locally.
62-
- (void)disabled_testGetFID {
65+
- (void)testGetFID {
66+
if (![self isDefaultAppConfigured]) {
67+
return;
68+
}
69+
6370
NSString *FID1 = [self getFID];
6471
NSString *FID2 = [self getFID];
6572

6673
XCTAssertEqualObjects(FID1, FID2);
6774
}
6875

69-
- (void)disabled_testAuthToken {
76+
- (void)testAuthToken {
77+
if (![self isDefaultAppConfigured]) {
78+
return;
79+
}
80+
7081
XCTestExpectation *authTokenExpectation =
7182
[self expectationWithDescription:@"authTokenExpectation"];
7283

@@ -84,7 +95,11 @@ - (void)disabled_testAuthToken {
8495
[self waitForExpectations:@[ authTokenExpectation ] timeout:2];
8596
}
8697

87-
- (void)disabled_testDeleteInstallation {
98+
- (void)testDeleteInstallation {
99+
if (![self isDefaultAppConfigured]) {
100+
return;
101+
}
102+
88103
NSString *FIDBefore = [self getFID];
89104
FIRInstallationsAuthTokenResult *authTokenBefore = [self getAuthToken];
90105

@@ -111,20 +126,20 @@ - (void)testInstallationsWithApp {
111126

112127
// Wait for finishing all background operations.
113128
FBLWaitForPromisesWithTimeout(10);
114-
115-
[FIRApp resetApps];
116129
}
117130

118131
- (void)testDefaultAppInstallation {
132+
if (![self isDefaultAppConfigured]) {
133+
return;
134+
}
135+
119136
XCTAssertNotNil(self.installations);
120137
XCTAssertEqualObjects(self.installations.appOptions.googleAppID,
121138
[FIRApp defaultApp].options.googleAppID);
122139
XCTAssertEqualObjects(self.installations.appName, [FIRApp defaultApp].name);
123140

124141
// Wait for finishing all background operations.
125142
FBLWaitForPromisesWithTimeout(10);
126-
127-
[FIRApp resetApps];
128143
}
129144

130145
#endif // !TARGET_OS_OSX
@@ -197,6 +212,30 @@ - (FIRApp *)createAndConfigureAppWithName:(NSString *)name {
197212
return [FIRApp appNamed:name];
198213
}
199214

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+
}
201221

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

FirebaseInstallations/Source/Tests/Resources/GoogleService-Info.plist

Lines changed: 0 additions & 28 deletions
This file was deleted.

scripts/install_prereqs.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function install_secrets() {
2626
# requests from forks. See
2727
# https://docs.travis-ci.com/user/pull-requests#pull-requests-and-security-restrictions
2828
if [[ ! -z $encrypted_d6a88994a5ab_key ]]; then
29-
openssl aes-256-cbc -K $encrypted_b02643c8c602_key -iv $encrypted_b02643c8c602_iv \
29+
openssl aes-256-cbc -K $encrypted_3360571ebe7a_key -iv $encrypted_3360571ebe7a_iv \
3030
-in scripts/travis-encrypted/Secrets.tar.enc \
3131
-out scripts/travis-encrypted/Secrets.tar -d
3232

@@ -43,6 +43,11 @@ function install_secrets() {
4343
cp Secrets/Storage/App/GoogleService-Info.plist Example/Database/App/GoogleService-Info.plist
4444

4545
cp Secrets/Metrics/database.config Metrics/database.config
46+
47+
# Firebase Installations
48+
fis_resources_dir=FirebaseInstallations/Source/Tests/Resources/
49+
mkdir -p "$fis_resources_dir"
50+
cp Secrets/Installations/GoogleService-Info.plist "$fis_resources_dir"
4651
fi
4752
}
4853

@@ -98,6 +103,10 @@ case "$PROJECT-$PLATFORM-$METHOD" in
98103
install_secrets
99104
;;
100105

106+
Installations-*)
107+
install_secrets
108+
;;
109+
101110
InAppMessaging-iOS-xcodebuild)
102111
gem install xcpretty
103112
bundle exec pod install --project-directory=InAppMessagingDisplay/Example --repo-update
63 KB
Binary file not shown.

0 commit comments

Comments
 (0)