forked from GoogleCloudPlatform/python-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart_test.py
More file actions
55 lines (45 loc) · 1.63 KB
/
Copy pathquickstart_test.py
File metadata and controls
55 lines (45 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
# Copyright 2022 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
#
# 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.
import os
import quickstart as gke_list
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
ZONE = "us-central1-b"
def test_list_clusters(capsys: object) -> None:
output_prefix = "There were "
output_suffix = f" clusters in {ZONE} for project {PROJECT_ID}."
gke_list.list_clusters(PROJECT_ID, ZONE)
out, _ = capsys.readouterr()
"""
Typical output looks as follows:
There were 3 clusters in us-central1-b for project test-project.
- cluster1
- cluster2
- cluster3
Split array by '\n'
[
"There were 3 clusters in us-central1-b for project test-project.",
"- cluster1",
"- cluster2",
"- cluster3",
"",
]
"""
out_lines = out.split("\n")
first_line = out_lines[0]
first_line = first_line.replace(output_prefix, "")
first_line = first_line.replace(output_suffix, "")
cluster_count = int(first_line) # get the cluster count in the first line
assert output_suffix in out
assert cluster_count == len(out_lines) - 2