Skip to content

Commit 6a19548

Browse files
jbachemelnucfin
authored andcommitted
firestore: cross-language tests (#4359)
* firestore: cross-language tests Copied the cross-language tests from GoogleCloudPlatform/google-cloud-common to this repo. Generated the Python _pb2.py file for the test proto. This required some path renaming, so I added a Makefile. Added a unit test that reads and runs the test protos. Sorted transform paths in get_transform_pb to make some tests pass. Renamed tests that fail. TODOs: - Fix failing tests. - Support tests of the set() method. - Find a better place to put test_pb2.py. I don't understand how import paths work so I couldn't figure this out. * create client with project, instead of adding it later * sort update mask for tests
1 parent 460b606 commit 6a19548

102 files changed

Lines changed: 3426 additions & 948 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

firestore/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This makefile builds the protos needed for cross-language Firestore tests.
2+
3+
# Assume protoc is on the path. The proto compiler must be one that
4+
# supports proto3 syntax.
5+
PROTOC = protoc
6+
7+
# Dependent repos.
8+
PROTOBUF_REPO = $(HOME)/git-repos/protobuf
9+
GOOGLEAPIS_REPO = $(HOME)/git-repos/googleapis
10+
11+
TESTS_REPO = $(HOME)/git-repos/gcp/google-cloud-common
12+
13+
TMPDIR = /tmp/python-fs-proto
14+
TMPDIR_FS = $(TMPDIR)/google/cloud/firestore_v1beta1/proto
15+
16+
.PHONY: sync-protos gen-protos
17+
18+
gen-protos: sync-protos tweak-protos
19+
# TODO(jba): Put the generated proto somewhere more suitable.
20+
$(PROTOC) --python_out=google/cloud/firestore_v1beta1/proto \
21+
-I $(TMPDIR) \
22+
-I $(PROTOBUF_REPO)/src \
23+
-I $(GOOGLEAPIS_REPO) \
24+
$(TMPDIR)/*.proto
25+
26+
tweak-protos:
27+
mkdir -p $(TMPDIR_FS)
28+
cp $(GOOGLEAPIS_REPO)/google/firestore/v1beta1/*.proto $(TMPDIR_FS)
29+
sed -i -e 's@google/firestore/v1beta1@google/cloud/firestore_v1beta1/proto@' $(TMPDIR_FS)/*.proto
30+
cp $(TESTS_REPO)/testing/firestore/proto/*.proto $(TMPDIR)
31+
sed -i -e 's@google/firestore/v1beta1@google/cloud/firestore_v1beta1/proto@' $(TMPDIR)/*.proto
32+
33+
sync-protos:
34+
cd $(PROTOBUF_REPO); git pull
35+
cd $(GOOGLEAPIS_REPO); git pull
36+
cd $(TESTS_REPO); git pull

firestore/google/cloud/firestore_v1beta1/_helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ def get_transform_pb(document_path, transform_paths):
794794
field_path=field_path,
795795
set_to_server_value=REQUEST_TIME_ENUM,
796796
)
797-
for field_path in transform_paths
797+
# Sort transform_paths so test comparision works.
798+
for field_path in sorted(transform_paths)
798799
],
799800
),
800801
)
@@ -865,7 +866,8 @@ def pbs_for_update(client, document_path, field_updates, option):
865866
name=document_path,
866867
fields=encode_dict(update_values),
867868
),
868-
update_mask=common_pb2.DocumentMask(field_paths=field_paths),
869+
# Sort field_paths just for comparison in tests.
870+
update_mask=common_pb2.DocumentMask(field_paths=sorted(field_paths)),
869871
)
870872
# Due to the default, we don't have to check if ``None``.
871873
option.modify_write(update_pb)

0 commit comments

Comments
 (0)