Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix image name and tag merging #146

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pygluu/kubernetes/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ def prompt_version(self):
)

image_names_and_tags = versions.get(self.settings["GLUU_VERSION"], {})
self.settings.update(image_names_and_tags)
# override non-empty image name and tag
self.settings.update({
k: v for k, v in image_names_and_tags.items()
if not self.settings.get(k, "")
})

def confirm_params(self):
"""Formats output of settings from prompts to the user. Passwords are not displayed.
Expand Down
26 changes: 22 additions & 4 deletions tests/test_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def prompter():
from pygluu.kubernetes.prompt import Prompt

prompt = Prompt(accept_license=True, version="4.2.0_01")
prompt = Prompt(accept_license=True, version="4.2")

yield prompt

Expand Down Expand Up @@ -36,12 +36,30 @@ def test_prompt_license_no_prompt(prompter):

def test_prompt_version_no_prompt(prompter):
prompter.prompt_version()
assert prompter.settings["GLUU_VERSION"] == "4.2.0_01"
assert prompter.settings["GLUU_VERSION"] == "4.2"


@pytest.mark.parametrize("given, expected", [
("", "4.2.0_01"), # default if empty
("4.2.1_dev", "4.2.1_dev"), # non-empty shouldn't be overriden
])
def test_prompt_version_merge_names_tags(prompter, given, expected):
import json

with open("./gluu_versions.json", "w") as f:
json.dump({"4.2": {"LDAP_IMAGE_TAG": "4.2.0_01"}}, f)

prompter.settings["LDAP_IMAGE_TAG"] = given
prompter.prompt_version()
assert prompter.settings["LDAP_IMAGE_TAG"] == expected

with contextlib.suppress(FileNotFoundError):
os.unlink("./gluu_versions.json")


@pytest.mark.parametrize("given, expected", [
("", "0"),
("4.2.0_01", "4.2.0_01"),
("4.2", "4.2"),
])
def test_prompt_version(monkeypatch, prompter, given, expected):
monkeypatch.setattr("click.prompt", lambda x, default: given or expected)
Expand Down Expand Up @@ -216,7 +234,7 @@ def test_prompt_helm_gg_ui_helm_release_name(monkeypatch, prompter, given, expec

@pytest.mark.parametrize("given, expected", [
("", "0"),
("4.2.0_01", "4.2.0_01"),
("4.2", "4.2"),
])
def test_prompt_upgrade_version(monkeypatch, prompter, given, expected):
monkeypatch.setattr("click.prompt", lambda x, default: given or expected)
Expand Down