Skip to content

Commit

Permalink
path fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Franr committed May 25, 2024
1 parent cab31dc commit 331d049
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
2 changes: 1 addition & 1 deletion leverage/containers/kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class KubeCtlContainer(TerraformContainer):
"""Container specifically tailored to run kubectl commands."""

KUBECTL_CLI_BINARY = "/usr/local/bin/kubectl"
KUBECTL_CONFIG_PATH = Path("/root/.kube")
KUBECTL_CONFIG_PATH = Path("/home/leverage/.kube")
KUBECTL_CONFIG_FILE = KUBECTL_CONFIG_PATH / Path("config")

def __init__(self, client):
Expand Down
2 changes: 1 addition & 1 deletion leverage/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def backend_tfvars(self):

@property
def guest_aws_credentials_dir(self):
return str(get_home_path() / Path(self.project))
return str("/home/leverage/tmp" / Path(self.project))

@property
def host_aws_profiles_file(self):
Expand Down
48 changes: 17 additions & 31 deletions tests/test_modules/test_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from click import get_current_context

from leverage._internals import State
from leverage._utils import AwsCredsContainer
from leverage.container import TerraformContainer
from leverage.modules.terraform import _init
from tests.test_containers import container_fixture_factory
Expand All @@ -22,36 +21,23 @@ def terraform_container(muted_click_context):

# assume we are on a valid location
with patch.object(tf_container.paths, "check_for_layer_location", Mock()):
# assume we have valid credentials
with patch.object(AwsCredsContainer, "__enter__", Mock()):
yield tf_container


def test_init(terraform_container):
"""
Test happy path.
"""
live_container = Mock()
with patch("leverage._utils.LiveContainer.__enter__", return_value=live_container):
with patch("dockerpty.exec_command") as mocked_pty:
_init([])

assert live_container.exec_run.call_args_list[0].args[0] == "mkdir -p /root/.ssh"
assert live_container.exec_run.call_args_list[1].args[0] == "chown root:root -R /root/.ssh/"
assert (
mocked_pty.call_args_list[0].kwargs["command"]
== f"terraform init -backend-config=/project/./config/backend.tfvars"
)


def test_init_with_args(terraform_container):
yield tf_container


@pytest.mark.parametrize(
"args, expected_value",
[
([], ["-backend-config=/project/./config/backend.tfvars"]),
(["-migrate-state"], ["-migrate-state", "-backend-config=/project/./config/backend.tfvars"]),
(["-r1", "-r2"], ["-r1", "-r2", "-backend-config=/project/./config/backend.tfvars"]),
],
)
def test_init_arguments(terraform_container, args, expected_value):
"""
Test tf init with arguments.
Test that the arguments for the init command are prepared correctly.
"""
with patch("dockerpty.exec_command") as mocked_pty:
_init(["-migrate-state"])
with patch.object(terraform_container, "start_in_layer", return_value=0) as mocked:
_init(args)

assert (
mocked_pty.call_args_list[0].kwargs["command"]
== f"terraform init -migrate-state -backend-config=/project/./config/backend.tfvars"
)
assert mocked.call_args_list[0][0][0] == "init"
assert " ".join(mocked.call_args_list[0][0][1:]) == " ".join(expected_value)

0 comments on commit 331d049

Please sign in to comment.