This repository was archived by the owner on Mar 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
test: add system tests #420
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d0a2514
test: add system tests
olavloite 09ad9c4
test: run system tests on prod
olavloite bab0414
build: allow any Python version for sys tests
olavloite e517c87
build: keep instance and create new databases instead
olavloite dcb4e2b
chore: format code
olavloite ac2e34b
fix: do not use static fallback config
olavloite bcc8893
fix: cleanup job
olavloite 3fe2953
fix: search until end of string
olavloite 764f4af
Merge branch 'main' into system-tests
olavloite 6f6a264
build: only run system tests on the emulator for presubmits
olavloite a182f86
build: skip system tests when skipping conformance tests
olavloite aa6ce6e
test: run tests with Python 3.8
olavloite daddd1d
test: try this
olavloite 383f1a0
test: no tests
olavloite 229af23
Merge branch 'main' into system-tests
olavloite c6c4a48
build: run system tests on real Spanner
olavloite 43dbd26
chore: cleanup test database after system test run
olavloite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import configparser | ||
| import os | ||
| import re | ||
| import time | ||
|
|
||
| from create_test_config import set_test_config | ||
| from google.api_core import datetime_helpers | ||
| from google.api_core.exceptions import AlreadyExists, ResourceExhausted | ||
| from google.cloud.spanner_v1 import Client | ||
| from google.cloud.spanner_v1.instance import Instance | ||
| from google.cloud.spanner_v1.database import Database | ||
|
|
||
|
|
||
| USE_EMULATOR = os.getenv("SPANNER_EMULATOR_HOST") is not None | ||
|
|
||
| PROJECT = os.getenv( | ||
| "GOOGLE_CLOUD_PROJECT", | ||
| os.getenv("PROJECT_ID", "emulator-test-project"), | ||
| ) | ||
| CLIENT = None | ||
|
|
||
| if USE_EMULATOR: | ||
| from google.auth.credentials import AnonymousCredentials | ||
|
|
||
| CLIENT = Client(project=PROJECT, credentials=AnonymousCredentials()) | ||
| else: | ||
| CLIENT = Client(project=PROJECT) | ||
|
|
||
|
|
||
| def delete_test_database(): | ||
| """Delete the currently configured test database.""" | ||
| config = configparser.ConfigParser() | ||
| if os.path.exists("test.cfg"): | ||
| config.read("test.cfg") | ||
| else: | ||
| config.read("setup.cfg") | ||
| db_url = config.get("db", "default") | ||
|
|
||
| instance_id = re.findall(r"instances(.*?)databases", db_url) | ||
| database_id = re.findall(r"databases(.*?)$", db_url) | ||
|
|
||
| instance = CLIENT.instance( | ||
| instance_id="".join(instance_id).replace("/", "")) | ||
| database = instance.database("".join(database_id).replace("/", "")) | ||
| database.drop() | ||
|
|
||
| delete_test_database() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Copyright 2024 Google LLC All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from sqlalchemy import text, Table, Column, Integer, PrimaryKeyConstraint, String | ||
| from sqlalchemy.testing import eq_ | ||
| from sqlalchemy.testing.plugin.plugin_base import fixtures | ||
|
|
||
|
|
||
| class TestBasics(fixtures.TablesTest): | ||
| @classmethod | ||
| def define_tables(cls, metadata): | ||
| Table( | ||
| "numbers", | ||
| metadata, | ||
| Column("number", Integer), | ||
| Column("name", String(20)), | ||
| PrimaryKeyConstraint("number"), | ||
| ) | ||
|
|
||
| def test_hello_world(self, connection): | ||
| greeting = connection.execute(text("select 'Hello World'")) | ||
| eq_("Hello World", greeting.fetchone()[0]) | ||
|
|
||
| def test_insert_number(self, connection): | ||
| connection.execute( | ||
| text("insert or update into numbers(number, name) values (1, 'One')") | ||
| ) | ||
| name = connection.execute(text("select name from numbers where number=1")) | ||
| eq_("One", name.fetchone()[0]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If my understanding is correct, we cleanup the databases only when a new system test is run, right? Do we want to keep the database around to check for errors? Shouldn't we do a cleanup post the system tests being run as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, we were only cleaning up during the following run (and then only databases older than 4 hours). I've added a cleanup job that is executed after the system tests have executed.