Check error output for entrypoint tests
This commit is contained in:
Родитель
99b11cbf93
Коммит
3725a64e31
|
@ -72,13 +72,6 @@ jobs:
|
|||
circleci step halt
|
||||
fi
|
||||
- *build
|
||||
- run:
|
||||
name: Install bq
|
||||
command: |
|
||||
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
|
||||
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
|
||||
PATH="venv/bin:$PATH" apt-get update && PATH="venv/bin:$PATH" apt-get install google-cloud-sdk -y
|
||||
cp .bigqueryrc /root/.bigqueryrc
|
||||
- &pytest_integration_test
|
||||
run:
|
||||
name: PyTest Integration Test
|
||||
|
@ -86,6 +79,8 @@ jobs:
|
|||
# and use a file in that location for credentials if present;
|
||||
# See https://cloud.google.com/docs/authentication/production
|
||||
command: |
|
||||
export GOOGLE_APPLICATION_CREDENTIALS="/tmp/gcp.json"
|
||||
echo "$GCLOUD_SERVICE_KEY" > "$GOOGLE_APPLICATION_CREDENTIALS"
|
||||
PATH="venv/bin:$PATH" script/entrypoint -m integration
|
||||
validate-dags:
|
||||
# based on https://github.com/mozilla/telemetry-airflow/blob/master/.circleci/config.yml
|
||||
|
|
|
@ -16,10 +16,27 @@ class TestEntrypoint:
|
|||
query_file = query_file_path / "query.sql"
|
||||
query_file.write_text("SELECT 1 AS a, 'abc' AS b;")
|
||||
|
||||
result = subprocess.check_call(
|
||||
[ENTRYPOINT_SCRIPT, "query", "--project_id=" + project_id, str(query_file)]
|
||||
)
|
||||
assert result == 0
|
||||
try:
|
||||
result = subprocess.check_output(
|
||||
[
|
||||
ENTRYPOINT_SCRIPT,
|
||||
"query",
|
||||
"--project_id=" + project_id,
|
||||
str(query_file),
|
||||
],
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
assert b"Current status: DONE" in result
|
||||
assert b"No metadata.yaml found for {}" in result
|
||||
except subprocess.CalledProcessError as e:
|
||||
# running bq in CircleCI will fail since it's not installed
|
||||
# but the error output can be checked for whether bq was called
|
||||
assert b"No such file or directory: 'bq'" in e.output
|
||||
assert b"No metadata.yaml found for {}" in e.output
|
||||
assert (
|
||||
b'subprocess.check_call(["bq"] + query_arguments, stdin=query_stream)'
|
||||
in e.output
|
||||
)
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_query_write_to_table(
|
||||
|
@ -37,25 +54,35 @@ class TestEntrypoint:
|
|||
)
|
||||
bigquery_client.create_table(table)
|
||||
|
||||
result = subprocess.check_call(
|
||||
[
|
||||
ENTRYPOINT_SCRIPT,
|
||||
"query",
|
||||
"--dataset_id=" + temporary_dataset,
|
||||
"--destination_table=query_v1",
|
||||
"--project_id=" + project_id,
|
||||
"--replace",
|
||||
str(query_file),
|
||||
]
|
||||
)
|
||||
assert result == 0
|
||||
try:
|
||||
result = subprocess.check_output(
|
||||
[
|
||||
ENTRYPOINT_SCRIPT,
|
||||
"query",
|
||||
"--dataset_id=" + temporary_dataset,
|
||||
"--destination_table=query_v1",
|
||||
"--project_id=" + project_id,
|
||||
"--replace",
|
||||
str(query_file),
|
||||
],
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
assert b"Current status: DONE" in result
|
||||
assert b"No metadata.yaml found for {}" in result
|
||||
|
||||
result = bigquery_client.query(
|
||||
f"SELECT a FROM {project_id}.{temporary_dataset}.query_v1"
|
||||
).result()
|
||||
assert result.total_rows == 1
|
||||
for row in result:
|
||||
assert row.a == "foo"
|
||||
result = bigquery_client.query(
|
||||
f"SELECT a FROM {project_id}.{temporary_dataset}.query_v1"
|
||||
).result()
|
||||
assert result.total_rows == 1
|
||||
for row in result:
|
||||
assert row.a == "foo"
|
||||
except subprocess.CalledProcessError as e:
|
||||
assert b"No such file or directory: 'bq'" in e.output
|
||||
assert b"No metadata.yaml found for {}" in e.output
|
||||
assert (
|
||||
b'subprocess.check_call(["bq"] + query_arguments, stdin=query_stream)'
|
||||
in e.output
|
||||
)
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_query_no_query_file(self):
|
||||
|
|
Загрузка…
Ссылка в новой задаче