add tests
This commit is contained in:
parent
aad4500107
commit
437caa437e
|
|
@ -11,7 +11,7 @@ def execute(args):
|
||||||
tenant_name = args.tenant_name
|
tenant_name = args.tenant_name
|
||||||
target_directory = args.target
|
target_directory = args.target
|
||||||
|
|
||||||
tenant_directory = os.path.join(target_directory, "tenants", tenant_name)
|
tenant_directory = os.path.join(target_directory, tenant_name)
|
||||||
|
|
||||||
# Check if the tenant directory already exists
|
# Check if the tenant directory already exists
|
||||||
if os.path.exists(tenant_directory):
|
if os.path.exists(tenant_directory):
|
||||||
|
|
@ -29,4 +29,18 @@ def execute(args):
|
||||||
os.makedirs(kubernetes_directory)
|
os.makedirs(kubernetes_directory)
|
||||||
os.makedirs(certificates_directory)
|
os.makedirs(certificates_directory)
|
||||||
|
|
||||||
|
# Create symbolic links for *.tf files
|
||||||
|
source_tf_dir = os.path.join(target_directory, "terraform")
|
||||||
|
target_tf_dir = os.path.join(tenant_directory, "terraform")
|
||||||
|
|
||||||
|
for filename in os.listdir(source_tf_dir):
|
||||||
|
if filename.endswith(".tf"):
|
||||||
|
source_path = os.path.join(source_tf_dir, filename)
|
||||||
|
target_path = os.path.join(target_tf_dir, filename)
|
||||||
|
# Ensure the source path is correct before creating the symbolic link
|
||||||
|
if os.path.exists(source_path):
|
||||||
|
relative_path = os.path.relpath(source_path, target_tf_dir)
|
||||||
|
os.symlink(relative_path, target_path)
|
||||||
|
else:
|
||||||
|
print(f"Warning: Source file '{filename}' not found in '{source_tf_dir}'.")
|
||||||
print(f"Tenant '{tenant_name}' initialized in '{tenant_directory}' with GitSync password provided.")
|
print(f"Tenant '{tenant_name}' initialized in '{tenant_directory}' with GitSync password provided.")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
# tests/test_init.py
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
from argparse import Namespace # Import Namespace for creating args object
|
||||||
|
from tenant.commands import init
|
||||||
|
|
||||||
|
class TestInitCommand(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
# Set up any necessary configurations or resources
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
# Clean up after the test
|
||||||
|
pass
|
||||||
|
|
||||||
|
@patch("tenant.commands.init.get_secure_password", return_value="mocked_password")
|
||||||
|
def test_init_command(self, mock_input):
|
||||||
|
tenant_name = "test-tenant"
|
||||||
|
target_directory = "/tmp/test"
|
||||||
|
|
||||||
|
# Ensure the tenant directory doesn't exist before running the test
|
||||||
|
tenant_directory = os.path.join(target_directory, "tenants", tenant_name)
|
||||||
|
if os.path.exists(tenant_directory):
|
||||||
|
os.rmdir(tenant_directory)
|
||||||
|
|
||||||
|
# Create an args object
|
||||||
|
args = Namespace(command="init", tenant_name=tenant_name, target=target_directory)
|
||||||
|
|
||||||
|
# Call the init command with the args object
|
||||||
|
init.execute(args)
|
||||||
|
|
||||||
|
# Verify that the tenant directory has been created
|
||||||
|
self.assertTrue(os.path.exists(tenant_directory))
|
||||||
|
self.assertTrue(os.path.exists(os.path.join(tenant_directory, "terraform")))
|
||||||
|
self.assertTrue(os.path.exists(os.path.join(tenant_directory, "kubernetes")))
|
||||||
|
self.assertTrue(os.path.exists(os.path.join(tenant_directory, "certificates")))
|
||||||
|
|
||||||
|
# Clean up: Remove the created tenant directory
|
||||||
|
os.rmdir(os.path.join(tenant_directory, "terraform"))
|
||||||
|
os.rmdir(os.path.join(tenant_directory, "kubernetes"))
|
||||||
|
os.rmdir(os.path.join(tenant_directory, "certificates"))
|
||||||
|
os.rmdir(tenant_directory)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Loading…
Reference in New Issue