Skip to content

Commit

Permalink
Update conformance tests to match new repo / format. (#8689)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tseaver authored Jul 17, 2019
1 parent 29b3c4d commit 563effc
Show file tree
Hide file tree
Showing 449 changed files with 12,385 additions and 9,168 deletions.
17 changes: 10 additions & 7 deletions firestore/Makefile_v1
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,33 @@ PROTOC = protoc
REPO_DIR=$(HOME)/git-repos
PROTOBUF_REPO = $(REPO_DIR)/protobuf
GOOGLEAPIS_REPO = $(REPO_DIR)/googleapis
TESTS_REPO = $(REPO_DIR)/gcp/google-cloud-common
TESTS_REPO = $(REPO_DIR)/conformance-tests
TEST_PROTO_DIR = $(TESTS_REPO)/firestore/v1
TEST_PROTO_SRC = $(TEST_PROTO_DIR)/proto/google/cloud/conformance/firestore/v1/tests.proto

TMPDIR = /tmp/python-fs-proto
TMPDIR_FS = $(TMPDIR)/google/cloud/firestore_v1/proto
TEST_PROTO_COPY = $(TMPDIR_FS)/tests.proto

.PHONY: sync-protos gen-protos

gen-protos: sync-protos tweak-protos
# TODO(jba): Put the generated proto somewhere more suitable.
$(PROTOC) --python_out=google/cloud/firestore_v1/proto \
$(PROTOC) --python_out=. \
-I $(TMPDIR) \
-I $(PROTOBUF_REPO)/src \
-I $(GOOGLEAPIS_REPO) \
$(TMPDIR)/test_v1.proto
$(TEST_PROTO_COPY)

tweak-protos:
mkdir -p $(TMPDIR_FS)
cp $(GOOGLEAPIS_REPO)/google/firestore/v1/*.proto $(TMPDIR_FS)
sed -i -e 's@google/firestore/v1@google/cloud/firestore_v1/proto@' $(TMPDIR_FS)/*.proto
cp $(TESTS_REPO)/testing/firestore/proto/test_v1.proto $(TMPDIR)
sed -i -e 's@package tests@package tests.v1@' $(TMPDIR)/test_v1.proto
sed -i -e 's@google/firestore/v1@google/cloud/firestore_v1/proto@' $(TMPDIR)/test_v1.proto
cp $(TEST_PROTO_SRC) $(TEST_PROTO_COPY)
sed -i -e 's@package google.cloud.conformance.firestore.v1@package google.cloud.firestore_v1.proto@' $(TEST_PROTO_COPY)
sed -i -e 's@google/firestore/v1@google/cloud/firestore_v1/proto@' $(TEST_PROTO_COPY)

sync-protos:
cd $(PROTOBUF_REPO); git pull
cd $(GOOGLEAPIS_REPO); git pull
#cd $(TESTS_REPO); git pull
cd $(TESTS_REPO); git pull
2,208 changes: 2,208 additions & 0 deletions firestore/google/cloud/firestore_v1/proto/tests_pb2.py

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions firestore/tests/unit/v1/test_cross_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@
import mock
import pytest

from google.protobuf import text_format
from google.protobuf import json_format
from google.cloud.firestore_v1.proto import document_pb2
from google.cloud.firestore_v1.proto import firestore_pb2
from google.cloud.firestore_v1.proto import test_v1_pb2
from google.cloud.firestore_v1.proto import tests_pb2
from google.cloud.firestore_v1.proto import write_pb2


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


_here = os.path.dirname(__file__)
_glob_expr = "{}/testdata/*.textproto".format(_here)
_glob_expr = "{}/testdata/*.json".format(_here)
_globs = glob.glob(_glob_expr)
ALL_TESTPROTOS = [_load_testproto(filename) for filename in sorted(_globs)]
ALL_TESTPROTOS = []
for filename in sorted(_globs):
ALL_TESTPROTOS.extend(_load_test_json(filename))

_CREATE_TESTPROTOS = [
test_proto
Expand Down
73 changes: 73 additions & 0 deletions firestore/tests/unit/v1/testdata/create-all-transforms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"tests": [
{
"description": "create: all transforms in a single call",
"comment": "A document can be created with any amount of transforms.",
"create": {
"docRefPath": "projects/projectID/databases/(default)/documents/C/d",
"jsonData": "{\"a\": 1, \"b\": \"ServerTimestamp\", \"c\": [\"ArrayUnion\", 1, 2, 3], \"d\": [\"ArrayRemove\", 4, 5, 6]}",
"request": {
"database": "projects/projectID/databases/(default)",
"writes": [
{
"update": {
"name": "projects/projectID/databases/(default)/documents/C/d",
"fields": {
"a": {
"integerValue": "1"
}
}
},
"currentDocument": {
"exists": false
}
},
{
"transform": {
"document": "projects/projectID/databases/(default)/documents/C/d",
"fieldTransforms": [
{
"fieldPath": "b",
"setToServerValue": "REQUEST_TIME"
},
{
"fieldPath": "c",
"appendMissingElements": {
"values": [
{
"integerValue": "1"
},
{
"integerValue": "2"
},
{
"integerValue": "3"
}
]
}
},
{
"fieldPath": "d",
"removeAllFromArray": {
"values": [
{
"integerValue": "4"
},
{
"integerValue": "5"
},
{
"integerValue": "6"
}
]
}
}
]
}
}
]
}
}
}
]
}
64 changes: 0 additions & 64 deletions firestore/tests/unit/v1/testdata/create-all-transforms.textproto

This file was deleted.

69 changes: 69 additions & 0 deletions firestore/tests/unit/v1/testdata/create-arrayremove-multi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"tests": [
{
"description": "create: multiple ArrayRemove fields",
"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\".",
"create": {
"docRefPath": "projects/projectID/databases/(default)/documents/C/d",
"jsonData": "{\"a\": 1, \"b\": [\"ArrayRemove\", 1, 2, 3], \"c\": {\"d\": [\"ArrayRemove\", 4, 5, 6]}}",
"request": {
"database": "projects/projectID/databases/(default)",
"writes": [
{
"update": {
"name": "projects/projectID/databases/(default)/documents/C/d",
"fields": {
"a": {
"integerValue": "1"
}
}
},
"currentDocument": {
"exists": false
}
},
{
"transform": {
"document": "projects/projectID/databases/(default)/documents/C/d",
"fieldTransforms": [
{
"fieldPath": "b",
"removeAllFromArray": {
"values": [
{
"integerValue": "1"
},
{
"integerValue": "2"
},
{
"integerValue": "3"
}
]
}
},
{
"fieldPath": "c.d",
"removeAllFromArray": {
"values": [
{
"integerValue": "4"
},
{
"integerValue": "5"
},
{
"integerValue": "6"
}
]
}
}
]
}
}
]
}
}
}
]
}

This file was deleted.

Loading

0 comments on commit 563effc

Please sign in to comment.