Skip to content

Commit

Permalink
tests(gce): unit tests for init config-parsing of service-account-email
Browse files Browse the repository at this point in the history
  • Loading branch information
blackboxsw committed Sep 17, 2024
1 parent 2dcb1fb commit 9e0a65e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/unit_tests/gce/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,50 @@ def gce(request, common_mocks, tmpdir):
class TestGCE:
"""General GCE testing."""

@pytest.mark.parametrize(
"toml_content,expected",
(
(
"[gce]\nservice_account_email = 'toml@mail.com'\n",
"toml@mail.com",
),
("[gce]\n", "service-acct@mail.com"),
),
)
def test_init_config_parsing_service_account_email(
self, toml_content, expected, common_mocks, tmpdir
):
"""
service_account_email comes from pycloudlib.toml fallback config_file.
"""
cfg_file = tmpdir.join("pyproject.toml")
cfg_file.write(toml_content)
gce = GCE(tag="pycl-tag", config_file=cfg_file.strpath)
assert expected == gce.service_account_email

@pytest.mark.parametrize(
"environ,cred_path,project",
[
({}, "", "my-project"),
(
{"GOOGLE_APPLICATION_CREDENTIALS": "other-file"},
"other-file",
"my-project",
),
({"GOOGLE_CLOUD_PROJECT": "env-project"}, "", "env-project"),
],
)
def test_init_config_parsing_from_environment(
self, environ, cred_path, project, common_mocks, tmpdir
):
with mock.patch.dict("os.environ", values=environ):
gce = GCE(
tag="pycl-tag",
config_file=tmpdir.join("pyproject.toml").strpath,
)
assert cred_path == gce.credentials_path
assert project == gce.project

@pytest.mark.parametrize("gce", [{}], indirect=True)
@pytest.mark.parametrize(
[
Expand Down

0 comments on commit 9e0a65e

Please sign in to comment.