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 unit test for vars CLI #132

Merged
merged 1 commit into from
Oct 2, 2023
Merged
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
27 changes: 19 additions & 8 deletions solutions_builder/cli/vars_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,57 @@
def test_replace_var_to_template():
# Test with equals and quotes
text = "project_id = \"not-replaced-yet\" # sb-var:project_id"
text = replace_var_to_template("project_id", text)
text, count = replace_var_to_template("project_id", text)
assert text == "project_id = \"{{project_id}}\" # sb-var:project_id"
assert count == 1

# Test with equals without quotes
text = "project_id = test # sb-var:project_id"
text = replace_var_to_template("project_id", text)
text, count = replace_var_to_template("project_id", text)
assert text == "project_id = {{project_id}} # sb-var:project_id"
assert count == 1

# Test with comma without quotes
text = "project_id: test # sb-var:project_id"
text = replace_var_to_template("project_id", text)
text, count = replace_var_to_template("project_id", text)
assert text == "project_id: {{project_id}} # sb-var:project_id"
assert count == 1

def test_replace_var_to_custom_template():
# Test with equals and quotes
text = "project_id = \"not-replaced-yet\" # sb-var:project_id:prefix-{{project_id}}-suffix"
text = replace_var_to_template("project_id", text, custom_template=True)
text, count = replace_var_to_template("project_id", text, custom_template=True)
assert text == "project_id = \"prefix-{{project_id}}-suffix\" # sb-var:project_id:prefix-{{project_id}}-suffix"
assert count == 1

def test_replace_var_to_value():
text = "project_id = \"not-replaced-yet\" # sb-var:project_id"
text = replace_var_to_value("project_id", "fake-id", text)
text, count = replace_var_to_value("project_id", "fake-id", text)
assert text == "project_id = \"fake-id\" # sb-var:project_id"
assert count == 1

text = " PROJECT_ID: not-replaced-yet # sb-var:project_id"
text = replace_var_to_value("project_id", "fake-id", text)
text, count = replace_var_to_value("project_id", "fake-id", text)
assert text == " PROJECT_ID: fake-id # sb-var:project_id"
assert count == 1

def test_replace_with_multiple_lines():
text = """
env:
PROJECT_ID: not-replaced-yet # sb-var:project_id
"""
text = replace_var_to_value("project_id", "fake-id", text)
text, count = replace_var_to_value("project_id", "fake-id", text)
assert text == """
env:
PROJECT_ID: fake-id # sb-var:project_id
"""
assert count == 1

def test_replace_var_to_value_custom_template():
text = "project_id = \"not-replaced-yet\" # sb-var:project_id:prefix-{{project_id}}-suffix"
text = replace_var_to_value("project_id", "fake-id", text)
text, count = replace_var_to_value("project_id", "fake-id", text)
assert text == "project_id = \"prefix-fake-id-suffix\" # sb-var:project_id:prefix-{{project_id}}-suffix"

# FIXME: it double-counted the changes, as both simple template and custom
# template both counts.
assert count == 2