Skip to content

Commit 8e032b1

Browse files
authored
Update conformance tests to match new repo / format. (#8689)
Update Makefile test proto builder: - Use new 'conformance_tests' repo. - Handle updated file hierarchy, etc. Use new JSON format in 'test_cross_language.py'. - Copy in JSON testcase files from 'conformance-tests' repo.
1 parent 1f8bbcc commit 8e032b1

File tree

449 files changed

+12385
-9168
lines changed

Some content is hidden

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

449 files changed

+12385
-9168
lines changed

packages/google-cloud-firestore/Makefile_v1

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,33 @@ PROTOC = protoc
88
REPO_DIR=$(HOME)/git-repos
99
PROTOBUF_REPO = $(REPO_DIR)/protobuf
1010
GOOGLEAPIS_REPO = $(REPO_DIR)/googleapis
11-
TESTS_REPO = $(REPO_DIR)/gcp/google-cloud-common
11+
TESTS_REPO = $(REPO_DIR)/conformance-tests
12+
TEST_PROTO_DIR = $(TESTS_REPO)/firestore/v1
13+
TEST_PROTO_SRC = $(TEST_PROTO_DIR)/proto/google/cloud/conformance/firestore/v1/tests.proto
1214

1315
TMPDIR = /tmp/python-fs-proto
1416
TMPDIR_FS = $(TMPDIR)/google/cloud/firestore_v1/proto
17+
TEST_PROTO_COPY = $(TMPDIR_FS)/tests.proto
1518

1619
.PHONY: sync-protos gen-protos
1720

1821
gen-protos: sync-protos tweak-protos
1922
# TODO(jba): Put the generated proto somewhere more suitable.
20-
$(PROTOC) --python_out=google/cloud/firestore_v1/proto \
23+
$(PROTOC) --python_out=. \
2124
-I $(TMPDIR) \
2225
-I $(PROTOBUF_REPO)/src \
2326
-I $(GOOGLEAPIS_REPO) \
24-
$(TMPDIR)/test_v1.proto
27+
$(TEST_PROTO_COPY)
2528

2629
tweak-protos:
2730
mkdir -p $(TMPDIR_FS)
2831
cp $(GOOGLEAPIS_REPO)/google/firestore/v1/*.proto $(TMPDIR_FS)
2932
sed -i -e 's@google/firestore/v1@google/cloud/firestore_v1/proto@' $(TMPDIR_FS)/*.proto
30-
cp $(TESTS_REPO)/testing/firestore/proto/test_v1.proto $(TMPDIR)
31-
sed -i -e 's@package tests@package tests.v1@' $(TMPDIR)/test_v1.proto
32-
sed -i -e 's@google/firestore/v1@google/cloud/firestore_v1/proto@' $(TMPDIR)/test_v1.proto
33+
cp $(TEST_PROTO_SRC) $(TEST_PROTO_COPY)
34+
sed -i -e 's@package google.cloud.conformance.firestore.v1@package google.cloud.firestore_v1.proto@' $(TEST_PROTO_COPY)
35+
sed -i -e 's@google/firestore/v1@google/cloud/firestore_v1/proto@' $(TEST_PROTO_COPY)
3336

3437
sync-protos:
3538
cd $(PROTOBUF_REPO); git pull
3639
cd $(GOOGLEAPIS_REPO); git pull
37-
#cd $(TESTS_REPO); git pull
40+
cd $(TESTS_REPO); git pull

packages/google-cloud-firestore/google/cloud/firestore_v1/proto/tests_pb2.py

Lines changed: 2208 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/google-cloud-firestore/tests/unit/v1/test_cross_language.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,30 @@
2020
import mock
2121
import pytest
2222

23-
from google.protobuf import text_format
23+
from google.protobuf import json_format
2424
from google.cloud.firestore_v1.proto import document_pb2
2525
from google.cloud.firestore_v1.proto import firestore_pb2
26-
from google.cloud.firestore_v1.proto import test_v1_pb2
26+
from google.cloud.firestore_v1.proto import tests_pb2
2727
from google.cloud.firestore_v1.proto import write_pb2
2828

2929

30-
def _load_testproto(filename):
30+
def _load_test_json(filename):
3131
with open(filename, "r") as tp_file:
32-
tp_text = tp_file.read()
33-
test_proto = test_v1_pb2.Test()
34-
text_format.Merge(tp_text, test_proto)
32+
tp_json = json.load(tp_file)
33+
test_file = tests_pb2.TestFile()
34+
json_format.ParseDict(tp_json, test_file)
3535
shortname = os.path.split(filename)[-1]
36-
test_proto.description = test_proto.description + " (%s)" % shortname
37-
return test_proto
36+
for test_proto in test_file.tests:
37+
test_proto.description = test_proto.description + " (%s)" % shortname
38+
yield test_proto
3839

3940

4041
_here = os.path.dirname(__file__)
41-
_glob_expr = "{}/testdata/*.textproto".format(_here)
42+
_glob_expr = "{}/testdata/*.json".format(_here)
4243
_globs = glob.glob(_glob_expr)
43-
ALL_TESTPROTOS = [_load_testproto(filename) for filename in sorted(_globs)]
44+
ALL_TESTPROTOS = []
45+
for filename in sorted(_globs):
46+
ALL_TESTPROTOS.extend(_load_test_json(filename))
4447

4548
_CREATE_TESTPROTOS = [
4649
test_proto
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "create: all transforms in a single call",
5+
"comment": "A document can be created with any amount of transforms.",
6+
"create": {
7+
"docRefPath": "projects/projectID/databases/(default)/documents/C/d",
8+
"jsonData": "{\"a\": 1, \"b\": \"ServerTimestamp\", \"c\": [\"ArrayUnion\", 1, 2, 3], \"d\": [\"ArrayRemove\", 4, 5, 6]}",
9+
"request": {
10+
"database": "projects/projectID/databases/(default)",
11+
"writes": [
12+
{
13+
"update": {
14+
"name": "projects/projectID/databases/(default)/documents/C/d",
15+
"fields": {
16+
"a": {
17+
"integerValue": "1"
18+
}
19+
}
20+
},
21+
"currentDocument": {
22+
"exists": false
23+
}
24+
},
25+
{
26+
"transform": {
27+
"document": "projects/projectID/databases/(default)/documents/C/d",
28+
"fieldTransforms": [
29+
{
30+
"fieldPath": "b",
31+
"setToServerValue": "REQUEST_TIME"
32+
},
33+
{
34+
"fieldPath": "c",
35+
"appendMissingElements": {
36+
"values": [
37+
{
38+
"integerValue": "1"
39+
},
40+
{
41+
"integerValue": "2"
42+
},
43+
{
44+
"integerValue": "3"
45+
}
46+
]
47+
}
48+
},
49+
{
50+
"fieldPath": "d",
51+
"removeAllFromArray": {
52+
"values": [
53+
{
54+
"integerValue": "4"
55+
},
56+
{
57+
"integerValue": "5"
58+
},
59+
{
60+
"integerValue": "6"
61+
}
62+
]
63+
}
64+
}
65+
]
66+
}
67+
}
68+
]
69+
}
70+
}
71+
}
72+
]
73+
}

packages/google-cloud-firestore/tests/unit/v1/testdata/create-all-transforms.textproto

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "create: multiple ArrayRemove fields",
5+
"comment": "A document can have more than one ArrayRemove field.\nSince all the ArrayRemove fields are removed, the only field in the update is \"a\".",
6+
"create": {
7+
"docRefPath": "projects/projectID/databases/(default)/documents/C/d",
8+
"jsonData": "{\"a\": 1, \"b\": [\"ArrayRemove\", 1, 2, 3], \"c\": {\"d\": [\"ArrayRemove\", 4, 5, 6]}}",
9+
"request": {
10+
"database": "projects/projectID/databases/(default)",
11+
"writes": [
12+
{
13+
"update": {
14+
"name": "projects/projectID/databases/(default)/documents/C/d",
15+
"fields": {
16+
"a": {
17+
"integerValue": "1"
18+
}
19+
}
20+
},
21+
"currentDocument": {
22+
"exists": false
23+
}
24+
},
25+
{
26+
"transform": {
27+
"document": "projects/projectID/databases/(default)/documents/C/d",
28+
"fieldTransforms": [
29+
{
30+
"fieldPath": "b",
31+
"removeAllFromArray": {
32+
"values": [
33+
{
34+
"integerValue": "1"
35+
},
36+
{
37+
"integerValue": "2"
38+
},
39+
{
40+
"integerValue": "3"
41+
}
42+
]
43+
}
44+
},
45+
{
46+
"fieldPath": "c.d",
47+
"removeAllFromArray": {
48+
"values": [
49+
{
50+
"integerValue": "4"
51+
},
52+
{
53+
"integerValue": "5"
54+
},
55+
{
56+
"integerValue": "6"
57+
}
58+
]
59+
}
60+
}
61+
]
62+
}
63+
}
64+
]
65+
}
66+
}
67+
}
68+
]
69+
}

packages/google-cloud-firestore/tests/unit/v1/testdata/create-arrayremove-multi.textproto

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

0 commit comments

Comments
 (0)