Skip to content

Commit 35f554b

Browse files
authored
Mila/multi db (#1321)
1 parent 26c09e5 commit 35f554b

File tree

13 files changed

+699
-143
lines changed

13 files changed

+699
-143
lines changed

firestore/integration_test_internal/src/firestore_integration_test.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,19 @@ Firestore* FirestoreIntegrationTest::TestFirestore(
116116
return TestFirestoreWithProjectId(name, /*project_id=*/"");
117117
}
118118

119+
Firestore* FirestoreIntegrationTest::TestFirestoreWithDatabaseId(
120+
const std::string& name, const std::string& database_id) const {
121+
return TestFirestoreWithProjectId(name, /*project_id=*/"", database_id);
122+
}
123+
119124
Firestore* FirestoreIntegrationTest::TestFirestoreWithProjectId(
120-
const std::string& name, const std::string& project_id) const {
125+
const std::string& name,
126+
const std::string& project_id,
127+
const std::string& database_id) const {
121128
for (const auto& entry : firestores_) {
122129
const FirestoreInfo& firestore_info = entry.second;
123-
if (firestore_info.name() == name) {
130+
if (firestore_info.name() == name &&
131+
firestore_info.database_id() == database_id) {
124132
return firestore_info.firestore();
125133
}
126134
}
@@ -129,9 +137,9 @@ Firestore* FirestoreIntegrationTest::TestFirestoreWithProjectId(
129137
if (apps_.find(app) == apps_.end()) {
130138
apps_[app] = std::unique_ptr<App>(app);
131139
}
132-
133-
Firestore* db = new Firestore(CreateTestFirestoreInternal(app));
134-
firestores_[db] = FirestoreInfo(name, std::unique_ptr<Firestore>(db));
140+
Firestore* db = new Firestore(CreateTestFirestoreInternal(app, database_id));
141+
firestores_[db] =
142+
FirestoreInfo(name, database_id, std::unique_ptr<Firestore>(db));
135143

136144
firestore::LocateEmulator(db);
137145
return db;

firestore/integration_test_internal/src/firestore_integration_test.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <mutex>
2626
#include <string>
2727
#include <unordered_map>
28+
#include <utility>
2829
#include <vector>
2930

3031
#include "app/meta/move.h"
@@ -49,7 +50,8 @@ const int kCheckIntervalMillis = 100;
4950
// The timeout of waiting for a Future or a listener.
5051
const int kTimeOutMillis = 15000;
5152

52-
FirestoreInternal* CreateTestFirestoreInternal(App* app);
53+
FirestoreInternal* CreateTestFirestoreInternal(
54+
App* app, const std::string& database_id = kDefaultDatabase);
5355

5456
App* GetApp();
5557
App* GetApp(const char* name, const std::string& override_project_id);
@@ -252,9 +254,16 @@ class FirestoreIntegrationTest : public testing::Test {
252254
Firestore* TestFirestore(const std::string& name = kDefaultAppName) const;
253255

254256
// Returns a Firestore instance for an app with the given `name`, associated
255-
// with the database with the given `project_id`.
256-
Firestore* TestFirestoreWithProjectId(const std::string& name,
257-
const std::string& project_id) const;
257+
// with the database with the given `project_id` and default `database_id`.
258+
Firestore* TestFirestoreWithProjectId(
259+
const std::string& name,
260+
const std::string& project_id,
261+
const std::string& database_id = kDefaultDatabase) const;
262+
263+
// Returns a Firestore instance for an app with the given `name`, associated
264+
// with the database with the given `database_id`.
265+
Firestore* TestFirestoreWithDatabaseId(const std::string& name,
266+
const std::string& database_id) const;
258267

259268
// Deletes the given `Firestore` instance, which must have been returned by a
260269
// previous invocation of `TestFirestore()`, and removes it from the cache of
@@ -419,15 +428,22 @@ class FirestoreIntegrationTest : public testing::Test {
419428
class FirestoreInfo {
420429
public:
421430
FirestoreInfo() = default;
422-
FirestoreInfo(const std::string& name, std::unique_ptr<Firestore> firestore)
423-
: name_(name), firestore_(std::move(firestore)) {}
431+
FirestoreInfo(const std::string& name,
432+
const std::string& database_id,
433+
std::unique_ptr<Firestore> firestore)
434+
: name_(name),
435+
database_id_(database_id),
436+
firestore_(std::move(firestore)) {}
424437

425438
const std::string& name() const { return name_; }
426439
Firestore* firestore() const { return firestore_.get(); }
440+
const std::string& database_id() const { return database_id_; }
441+
427442
void ReleaseFirestore() { firestore_.release(); }
428443

429444
private:
430445
std::string name_;
446+
std::string database_id_;
431447
std::unique_ptr<Firestore> firestore_;
432448
};
433449

0 commit comments

Comments
 (0)