Skip to content

Commit 54f1b1b

Browse files
authored
Setup integration tests against named db (#11638)
* Make tests work against named db * setup jobs
1 parent 7da314a commit 54f1b1b

File tree

8 files changed

+113
-13
lines changed

8 files changed

+113
-13
lines changed

.github/workflows/firestore.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,54 @@ jobs:
123123
run: scripts/third_party/travis/retry.sh scripts/build.sh Firestore ${{ runner.os }} cmake
124124

125125

126+
cmake-prod-db:
127+
# Don't run on private repo unless it is a PR.
128+
if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'
129+
needs: check
130+
131+
strategy:
132+
matrix:
133+
os: [macos-12]
134+
databaseId: [(default), test-db]
135+
136+
env:
137+
plist_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
138+
MINT_PATH: ${{ github.workspace }}/mint
139+
TARGET_DATABASE_ID: ${{ matrix.databaseId }}
140+
141+
runs-on: ${{ matrix.os }}
142+
steps:
143+
- uses: actions/checkout@v3
144+
- uses: mikehardy/buildcache-action@c87cea0ccd718971d6cc39e672c4f26815b6c126
145+
with:
146+
cache_key: ${{ matrix.os }}
147+
148+
- name: Prepare ccache
149+
uses: actions/cache@v3
150+
with:
151+
path: ~/.ccache
152+
key: firestore-ccache-${{ runner.os }}-${{ github.sha }}
153+
restore-keys: |
154+
firestore-ccache-${{ runner.os }}-
155+
156+
- name: Cache Mint packages
157+
uses: actions/cache@v3
158+
with:
159+
path: ${{ env.MINT_PATH }}
160+
key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}
161+
restore-keys: ${{ runner.os }}-mint-
162+
163+
- name: Install Secret GoogleService-Info.plist
164+
run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/firestore.plist.gpg \
165+
Firestore/Example/App/GoogleService-Info.plist "$plist_secret"
166+
167+
- name: Setup build
168+
run: scripts/install_prereqs.sh Firestore ${{ runner.os }} cmake
169+
170+
- name: Build and test
171+
run: scripts/third_party/travis/retry.sh scripts/build.sh Firestore ${{ runner.os }} cmake
172+
173+
126174
sanitizers:
127175
# Don't run on private repo unless it is a PR.
128176
if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'

Firestore/Example/Tests/Integration/API/FIRBundlesTests.mm

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ - (void)verifyErrorProgress:(FIRLoadBundleTaskProgress*)progress {
6969
}
7070

7171
- (std::string)defaultBundle {
72-
return CreateBundle(MakeString([FSTIntegrationTestCase projectID]));
72+
return CreateBundle(MakeString([FSTIntegrationTestCase projectID]),
73+
MakeString([FSTIntegrationTestCase databaseID]));
7374
}
7475

7576
- (std::string)bundleForProject:(NSString*)projectID {
76-
return CreateBundle(MakeString(projectID));
77+
return CreateBundle(MakeString(projectID), MakeString([FSTIntegrationTestCase databaseID]));
78+
}
79+
80+
- (std::string)bundleForDatabase:(NSString*)databaseID {
81+
return CreateBundle(MakeString([FSTIntegrationTestCase projectID]), MakeString(databaseID));
7782
}
7883

7984
- (void)verifyQueryResults {
@@ -248,4 +253,27 @@ - (void)testLoadBundlesFromOtherProjectFails {
248253
XCTAssertEqualObjects(progresses[1], result);
249254
}
250255

256+
- (void)testLoadBundlesFromOtherDatabaseFails {
257+
NSMutableArray* progresses = [[NSMutableArray alloc] init];
258+
__block FIRLoadBundleTaskProgress* result;
259+
XCTestExpectation* expectation = [self expectationWithDescription:@"loading complete"];
260+
auto bundle = [self bundleForDatabase:@"other-database"];
261+
FIRLoadBundleTask* task =
262+
[self.db loadBundle:[MakeNSString(bundle) dataUsingEncoding:NSUTF8StringEncoding]
263+
completion:^(FIRLoadBundleTaskProgress* progress, NSError* error) {
264+
result = progress;
265+
XCTAssertNotNil(error);
266+
[expectation fulfill];
267+
}];
268+
[task addObserver:^(FIRLoadBundleTaskProgress* progress) {
269+
[progresses addObject:progress];
270+
}];
271+
[self awaitExpectation:expectation];
272+
273+
XCTAssertEqual(2ul, progresses.count);
274+
[self verifyProgress:progresses[0] hasLoadedDocument:0];
275+
[self verifyErrorProgress:progresses[1]];
276+
XCTAssertEqualObjects(progresses[1], result);
277+
}
278+
251279
@end

Firestore/Example/Tests/Integration/API/FIRValidationTests.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,11 @@ - (void)testWritesWithReferencesToADifferentDatabaseFail {
300300
id data = @{@"foo" : ref};
301301
[self expectWrite:data
302302
toFailWithReason:
303-
[NSString
304-
stringWithFormat:@"Document Reference is for database different-db/(default) but "
305-
"should be for database %@/(default) (found in field foo)",
306-
[FSTIntegrationTestCase projectID]]];
303+
[NSString stringWithFormat:@"Document Reference is for database different-db/%@ but "
304+
"should be for database %@/%@ (found in field foo)",
305+
[FSTIntegrationTestCase databaseID],
306+
[FSTIntegrationTestCase projectID],
307+
[FSTIntegrationTestCase databaseID]]];
307308
}
308309

309310
- (void)testWritesWithReservedFieldsFail {

Firestore/Example/Tests/Util/FSTIntegrationTestCase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ extern "C" {
4747
/** Returns the default Firestore project ID for testing. */
4848
+ (NSString *)projectID;
4949

50+
/** Returns the default Firestore database ID for testing. */
51+
+ (NSString *)databaseID;
52+
5053
+ (bool)isRunningAgainstEmulator;
5154

5255
/** Returns a FirestoreSettings configured to use either hexa or the emulator. */

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
static const double kPrimingTimeout = 45.0;
8585

8686
static NSString *defaultProjectId;
87+
static NSString *defaultDatabaseId = @"(default)";
8788
static FIRFirestoreSettings *defaultSettings;
8889

8990
static bool runningAgainstEmulator = false;
@@ -186,6 +187,12 @@ + (void)setUpDefaults {
186187

187188
defaultSettings = [[FIRFirestoreSettings alloc] init];
188189

190+
// Setup database id to use.
191+
NSString *databaseId = [[NSProcessInfo processInfo] environment][@"TARGET_DATABASE_ID"];
192+
if (databaseId) {
193+
defaultDatabaseId = databaseId;
194+
}
195+
189196
// Check for a MobileHarness configuration, running against nightly or prod, which have live
190197
// SSL certs.
191198
NSString *project = [[NSProcessInfo processInfo] environment][@"PROJECT_ID"];
@@ -217,7 +224,8 @@ + (void)setUpDefaults {
217224
defaultProjectId = project;
218225
defaultSettings.host = host;
219226

220-
NSLog(@"Integration tests running against %@/%@", defaultSettings.host, defaultProjectId);
227+
NSLog(@"Integration tests running against %@/(%@:%@)", defaultSettings.host, defaultProjectId,
228+
defaultDatabaseId);
221229
return;
222230
}
223231

@@ -230,7 +238,8 @@ + (void)setUpDefaults {
230238
defaultSettings.host = host;
231239
}
232240

233-
NSLog(@"Integration tests running against %@/%@", defaultSettings.host, defaultProjectId);
241+
NSLog(@"Integration tests running against %@/(%@:%@)", defaultSettings.host, defaultProjectId,
242+
defaultDatabaseId);
234243
return;
235244
}
236245

@@ -256,6 +265,13 @@ + (NSString *)projectID {
256265
return defaultProjectId;
257266
}
258267

268+
+ (NSString *)databaseID {
269+
if (!defaultDatabaseId) {
270+
return @"(default)";
271+
}
272+
return defaultDatabaseId;
273+
}
274+
259275
+ (bool)isRunningAgainstEmulator {
260276
// The only way to determine whether or not we're running against the emulator is to figure out
261277
// which testing environment we're using. Essentially `setUpDefaults` determines
@@ -282,8 +298,9 @@ - (FIRFirestore *)firestoreWithApp:(FIRApp *)app {
282298
FIRSetLoggerLevel(FIRLoggerLevelDebug);
283299

284300
std::string projectID = MakeString(app.options.projectID);
301+
std::string databaseID = MakeString(defaultDatabaseId);
285302
FIRFirestore *firestore =
286-
[[FIRFirestore alloc] initWithDatabaseID:DatabaseId(projectID)
303+
[[FIRFirestore alloc] initWithDatabaseID:DatabaseId(projectID, databaseID)
287304
persistenceKey:MakeString(persistenceKey)
288305
authCredentialsProvider:_fakeAuthCredentialsProvider
289306
appCheckCredentialsProvider:_fakeAppCheckCredentialsProvider

Firestore/core/test/unit/testutil/bundle_builder.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,15 @@ std::vector<std::string> BundleTemplate() {
194194

195195
} // namespace
196196

197-
std::string CreateBundle(const std::string& project_id) {
197+
std::string CreateBundle(const std::string& project_id,
198+
const std::string& database_id) {
198199
std::string bundle;
199200

200201
auto bundle_template = BundleTemplate();
201202
for (size_t i = 1; i < bundle_template.size(); ++i) {
202-
auto element =
203-
absl::StrReplaceAll(bundle_template[i], {{"{projectId}", project_id}});
203+
auto element = absl::StrReplaceAll(
204+
bundle_template[i],
205+
{{"{projectId}", project_id}, {"(default)", database_id}});
204206
bundle.append(std::to_string(element.size()));
205207
bundle.append(std::move(element));
206208
}

Firestore/core/test/unit/testutil/bundle_builder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace firebase {
2222
namespace firestore {
2323
namespace testutil {
2424

25-
std::string CreateBundle(const std::string& project_id);
25+
std::string CreateBundle(const std::string& project_id,
26+
const std::string& database_id);
2627

2728
} // namespace testutil
2829
} // namespace firestore
554 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)