Skip to content

Commit 4b968e8

Browse files
authored
Adding e2e test for system-package sample and updating markdown noxfile_config (#3949)
1 parent d549c0d commit 4b968e8

File tree

4 files changed

+183
-2
lines changed

4 files changed

+183
-2
lines changed

run/markdown-preview/noxfile_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
TEST_CONFIG_OVERRIDE = {
2424
# You can opt out from the test for specific Python versions.
2525

26-
# We only run the e2e test in py37 session.
27-
'ignored_versions': ["2.7", "3.6", "3.8"],
26+
# We only run the cloud run tests in py38 session.
27+
'ignored_versions': ["2.7", "3.6", "3.7"],
2828

2929
# An envvar key for determining the project id to use. Change it
3030
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a

run/system-package/e2e_test.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Copyright 2020 Google, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This sample creates a secure two-service application running on Cloud Run.
16+
# This test builds and deploys the two secure services
17+
# to test that they interact properly together.
18+
19+
import os
20+
import subprocess
21+
from urllib import request
22+
import uuid
23+
24+
import pytest
25+
26+
27+
@pytest.fixture()
28+
def services():
29+
# Unique suffix to create distinct service names
30+
suffix = uuid.uuid4().hex
31+
project = os.environ['GOOGLE_CLOUD_PROJECT']
32+
33+
# Build and Deploy Cloud Run Services
34+
subprocess.run(
35+
[
36+
"gcloud",
37+
"builds",
38+
"submit",
39+
"--project",
40+
project,
41+
"--substitutions",
42+
f"_SUFFIX={suffix}",
43+
"--config",
44+
"e2e_test_setup.yaml",
45+
"--quiet",
46+
], check=True
47+
)
48+
49+
# Get the URL for the service and the token
50+
service = subprocess.run(
51+
[
52+
"gcloud",
53+
"run",
54+
"--project",
55+
project,
56+
"--platform=managed",
57+
"--region=us-central1",
58+
"services",
59+
"describe",
60+
f"sys-package-{suffix}",
61+
"--format=value(status.url)",
62+
],
63+
stdout=subprocess.PIPE,
64+
check=True
65+
).stdout.strip()
66+
67+
token = subprocess.run(
68+
["gcloud", "auth", "print-identity-token"], stdout=subprocess.PIPE,
69+
check=True
70+
).stdout.strip()
71+
72+
yield service, token
73+
74+
subprocess.run(
75+
["gcloud", "run", "services", "delete", f"sys-package-{suffix}",
76+
"--project", project, "--platform", "managed", "--region",
77+
"us-central1", "--quiet"],
78+
check=True
79+
)
80+
81+
82+
def test_end_to_end(services):
83+
service = services[0].decode()
84+
token = services[1].decode()
85+
data = (
86+
"diagram.png?dot=digraph G { A -> {B, C, D} -> {F} }".replace(" ", "%20"))
87+
print(service)
88+
print(f"{service}{data}")
89+
90+
req = request.Request(
91+
f"{service}/{data}",
92+
headers={
93+
"Authorization": f"Bearer {token}",
94+
},
95+
)
96+
97+
response = request.urlopen(req)
98+
assert response.status == 200
99+
100+
body = response.read()
101+
# Response is a png
102+
assert b"PNG" in body
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2020 Google, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
steps:
16+
- # Build the renderer image
17+
name: gcr.io/cloud-builders/docker:latest
18+
args: ['build', '--tag=gcr.io/$PROJECT_ID/sys-package-${_SUFFIX}', '.']
19+
20+
- # Push the container image to Container Registry
21+
name: gcr.io/cloud-builders/docker
22+
args: ['push', 'gcr.io/$PROJECT_ID/sys-package-${_SUFFIX}']
23+
24+
- # Deploy to Cloud Run
25+
name: gcr.io/cloud-builders/gcloud
26+
args:
27+
- run
28+
- deploy
29+
- sys-package-${_SUFFIX}
30+
- --image
31+
- gcr.io/$PROJECT_ID/sys-package-${_SUFFIX}
32+
- --region
33+
- us-central1
34+
- --platform
35+
- managed
36+
- --no-allow-unauthenticated
37+
38+
images:
39+
- 'gcr.io/$PROJECT_ID/sys-package-${_SUFFIX}'
40+

run/system-package/noxfile_config.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Default TEST_CONFIG_OVERRIDE for python repos.
16+
17+
# You can copy this file into your directory, then it will be inported from
18+
# the noxfile.py.
19+
20+
# The source of truth:
21+
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py
22+
23+
TEST_CONFIG_OVERRIDE = {
24+
# You can opt out from the test for specific Python versions.
25+
26+
# We only run the cloud run tests in py38 session.
27+
'ignored_versions': ["2.7", "3.6", "3.7"],
28+
29+
# An envvar key for determining the project id to use. Change it
30+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
31+
# build specific Cloud project. You can also use your own string
32+
# to use your own Cloud project.
33+
'gcloud_project_env': 'GCLOUD_PROJECT',
34+
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
35+
36+
# A dictionary you want to inject into your test. Don't put any
37+
# secrets here. These values will override predefined values.
38+
'envs': {},
39+
}

0 commit comments

Comments
 (0)