-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first approach: copy ssh files and use live containers * raise error message in case of unknown host * tests * fix tests * debugging CI * debugging CI 2 * force a command * tail alone * ubuntu 20.04 * skip auth if we don't have to * reverting debugging stuff * clarify function documentation * project.yaml validations on "project create" * timeout test * Revert "project.yaml validations on "project create"" This reverts commit 38381b4. * use a pty to exec the init command + adapt tests * tty true by default * no interactive * no interactive on CI
- Loading branch information
Showing
7 changed files
with
187 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from unittest.mock import patch, Mock | ||
|
||
import pytest | ||
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 | ||
|
||
|
||
@pytest.fixture | ||
def terraform_container(muted_click_context): | ||
tf_container = container_fixture_factory(TerraformContainer) | ||
|
||
# this is required because of the @pass_container decorator | ||
ctx = get_current_context() | ||
state = State() | ||
state.container = tf_container | ||
ctx.obj = state | ||
|
||
# assume we are on a valid location | ||
with patch.object(TerraformContainer, "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): | ||
""" | ||
Test tf init with arguments. | ||
""" | ||
with patch("dockerpty.exec_command") as mocked_pty: | ||
_init(["-migrate-state"]) | ||
|
||
assert ( | ||
mocked_pty.call_args_list[0].kwargs["command"] | ||
== f"terraform init -migrate-state -backend-config=/project/./config/backend.tfvars" | ||
) |