Skip to content

Commit 585cd82

Browse files
authored
feat(firestore): [PQ] add pipeline queries
1 parent 6752a49 commit 585cd82

25 files changed

+8190
-19
lines changed

firestore/client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const resourcePrefixHeader = "google-cloud-resource-prefix"
4747
// requestParamsHeader is routing header required to access named databases
4848
const reqParamsHeader = "x-goog-request-params"
4949

50-
// reqParamsHeaderVal constructs header from dbPath
50+
// reqParamsHeaderVal constructs header from dbPath.
5151
// dbPath is of the form projects/{project_id}/databases/{database_id}
5252
func reqParamsHeaderVal(dbPath string) string {
5353
splitPath := strings.Split(dbPath, "/")
@@ -181,6 +181,11 @@ func withRequestParamsHeader(ctx context.Context, requestParams string) context.
181181
return metadata.NewOutgoingContext(ctx, md)
182182
}
183183

184+
// Pipeline creates a PipelineSource to start building a Firestore pipeline.
185+
func (c *Client) Pipeline() *PipelineSource {
186+
return &PipelineSource{client: c}
187+
}
188+
184189
// Collection creates a reference to a collection with the given path.
185190
// A path is a sequence of IDs separated by slashes.
186191
//

firestore/integration_test.go

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,29 @@ import (
4747
"google.golang.org/protobuf/types/known/structpb"
4848
)
4949

50-
func TestMain(m *testing.M) {
51-
databaseIDs := []string{DefaultDatabaseID}
52-
databasesStr, ok := os.LookupEnv(envDatabases)
53-
if ok {
54-
databaseIDs = append(databaseIDs, strings.Split(databasesStr, ",")...)
55-
}
50+
type firestoreEdition int
51+
52+
const (
53+
editionStandard firestoreEdition = iota // 0
54+
editionEnterprise // 1
55+
)
56+
57+
const (
58+
envProjID = "GCLOUD_TESTS_GOLANG_FIRESTORE_PROJECT_ID"
59+
envPrivateKey = "GCLOUD_TESTS_GOLANG_FIRESTORE_KEY"
60+
envDatabases = "GCLOUD_TESTS_GOLANG_FIRESTORE_DATABASES"
61+
envEnterpriseDatabases = "GCLOUD_TESTS_GOLANG_FIRESTORE_ENTERPRISE_DATABASES"
62+
envEmulator = "FIRESTORE_EMULATOR_HOST"
63+
indexBuilding = "index is currently building"
64+
databaseIDKey = "databaseID"
65+
firestoreEditionKey = "edition"
66+
)
5667

68+
func TestMain(m *testing.M) {
5769
testParams = make(map[string]interface{})
58-
for _, databaseID := range databaseIDs {
59-
testParams["databaseID"] = databaseID
70+
for databaseID, edition := range parseDatabases() {
71+
testParams[databaseIDKey] = databaseID
72+
testParams[firestoreEditionKey] = edition
6073
initIntegrationTest()
6174
status := m.Run()
6275
if status != 0 {
@@ -68,13 +81,26 @@ func TestMain(m *testing.M) {
6881
os.Exit(0)
6982
}
7083

71-
const (
72-
envProjID = "GCLOUD_TESTS_GOLANG_FIRESTORE_PROJECT_ID"
73-
envPrivateKey = "GCLOUD_TESTS_GOLANG_FIRESTORE_KEY"
74-
envDatabases = "GCLOUD_TESTS_GOLANG_FIRESTORE_DATABASES"
75-
envEmulator = "FIRESTORE_EMULATOR_HOST"
76-
indexBuilding = "index is currently building"
77-
)
84+
func parseDatabases() map[string]firestoreEdition {
85+
databases := map[string]firestoreEdition{
86+
DefaultDatabaseID: editionStandard,
87+
}
88+
89+
databasesStr, ok := os.LookupEnv(envDatabases)
90+
if ok {
91+
for _, databaseID := range strings.Split(databasesStr, ",") {
92+
databases[databaseID] = editionStandard
93+
}
94+
}
95+
96+
databasesStr, ok = os.LookupEnv(envEnterpriseDatabases)
97+
if ok {
98+
for _, databaseID := range strings.Split(databasesStr, ",") {
99+
databases[databaseID] = editionEnterprise
100+
}
101+
}
102+
return databases
103+
}
78104

79105
var (
80106
iClient *Client
@@ -88,7 +114,7 @@ var (
88114
)
89115

90116
func initIntegrationTest() {
91-
databaseID := testParams["databaseID"].(string)
117+
databaseID := testParams[databaseIDKey].(string)
92118
log.Printf("Setting up tests to run on databaseID: %q\n", databaseID)
93119
flag.Parse() // needed for testing.Short()
94120
if testing.Short() {
@@ -2730,12 +2756,12 @@ func TestIntegration_NewClientWithDatabase(t *testing.T) {
27302756
}{
27312757
{
27322758
desc: "Success",
2733-
dbName: testParams["databaseID"].(string),
2759+
dbName: testParams[databaseIDKey].(string),
27342760
wantErr: false,
27352761
},
27362762
{
27372763
desc: "Error from NewClient bubbled to NewClientWithDatabase",
2738-
dbName: testParams["databaseID"].(string),
2764+
dbName: testParams[databaseIDKey].(string),
27392765
wantErr: true,
27402766
opt: []option.ClientOption{option.WithCredentialsFile("non existent filepath")},
27412767
},

0 commit comments

Comments
 (0)