Skip to content

Commit

Permalink
start writing tests for server config
Browse files Browse the repository at this point in the history
  • Loading branch information
bgunnar5 committed Jun 10, 2024
1 parent 8421d74 commit 0543ae4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
1 change: 0 additions & 1 deletion merlin/examples/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,4 @@ def setup_example(name, outdir):

LOG.info(f"Copying example '{name}' to {outdir}")
write_example(src_path, outdir)
print(f"example: {example}")
return example
4 changes: 2 additions & 2 deletions merlin/server/server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def generate_password(length, pass_command: str = None) -> str:
:return:: string value with given length
"""
if pass_command:
process = subprocess.run(pass_command.split(), shell=True, stdout=subprocess.PIPE)
return process.stdout
process = subprocess.run(pass_command, shell=True, capture_output=True, text=True)
return process.stdout.strip()

characters = list(string.ascii_letters + string.digits + "!@#$%^&*()")

Expand Down
43 changes: 43 additions & 0 deletions tests/unit/server/test_server_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Tests for the `server_config.py` module.
"""

import string

from merlin.server.server_config import (
PASSWORD_LENGTH,
check_process_file_format,
config_merlin_server,
create_server_config,
dump_process_file,
generate_password,
get_server_status,
parse_redis_output,
pull_process_file,
pull_server_config,
pull_server_image,
)


def test_generate_password_no_pass_command():
"""
Test the `generate_password` function with no password command.
This should generate a password of 256 (PASSWORD_LENGTH) random ASCII characters.
"""
generated_password = generate_password(PASSWORD_LENGTH)
assert len(generated_password) == PASSWORD_LENGTH
valid_ascii_chars = string.ascii_letters + string.digits + "!@#$%^&*()"
for ch in generated_password:
assert ch in valid_ascii_chars


def test_generate_password_with_pass_command():
"""
Test the `generate_password` function with no password command.
This should generate a password of 256 (PASSWORD_LENGTH) random ASCII characters.
"""
test_pass = "test-password"
generated_password = generate_password(0, pass_command=f"echo {test_pass}")
assert generated_password == test_pass


0 comments on commit 0543ae4

Please sign in to comment.