Skip to content

Commit 9e0a65e

Browse files
committed
tests(gce): unit tests for init config-parsing of service-account-email
1 parent 2dcb1fb commit 9e0a65e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/unit_tests/gce/test_cloud.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,50 @@ def gce(request, common_mocks, tmpdir):
5353
class TestGCE:
5454
"""General GCE testing."""
5555

56+
@pytest.mark.parametrize(
57+
"toml_content,expected",
58+
(
59+
(
60+
"[gce]\nservice_account_email = '[email protected]'\n",
61+
62+
),
63+
("[gce]\n", "[email protected]"),
64+
),
65+
)
66+
def test_init_config_parsing_service_account_email(
67+
self, toml_content, expected, common_mocks, tmpdir
68+
):
69+
"""
70+
service_account_email comes from pycloudlib.toml fallback config_file.
71+
"""
72+
cfg_file = tmpdir.join("pyproject.toml")
73+
cfg_file.write(toml_content)
74+
gce = GCE(tag="pycl-tag", config_file=cfg_file.strpath)
75+
assert expected == gce.service_account_email
76+
77+
@pytest.mark.parametrize(
78+
"environ,cred_path,project",
79+
[
80+
({}, "", "my-project"),
81+
(
82+
{"GOOGLE_APPLICATION_CREDENTIALS": "other-file"},
83+
"other-file",
84+
"my-project",
85+
),
86+
({"GOOGLE_CLOUD_PROJECT": "env-project"}, "", "env-project"),
87+
],
88+
)
89+
def test_init_config_parsing_from_environment(
90+
self, environ, cred_path, project, common_mocks, tmpdir
91+
):
92+
with mock.patch.dict("os.environ", values=environ):
93+
gce = GCE(
94+
tag="pycl-tag",
95+
config_file=tmpdir.join("pyproject.toml").strpath,
96+
)
97+
assert cred_path == gce.credentials_path
98+
assert project == gce.project
99+
56100
@pytest.mark.parametrize("gce", [{}], indirect=True)
57101
@pytest.mark.parametrize(
58102
[

0 commit comments

Comments
 (0)