Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Franr committed May 25, 2024
1 parent 331d049 commit 5e5b746
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
6 changes: 1 addition & 5 deletions tests/test_containers/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ def test_sso_login(mocked_new_tab, aws_container, fake_os_user, propagate_logs,

container_args = aws_container.client.api.create_container.call_args_list[0][1]
# make sure we: point to the correct script
assert container_args["command"] == "/root/scripts/aws-sso/aws-sso-login.sh"
assert container_args["command"] == "/opt/scripts/aws-sso/aws-sso-login.sh"
# the browser tab points to the correct code and the correct region
assert mocked_new_tab.call_args[0][0] == "https://device.sso.us-east-1.amazonaws.com/?user_code=TEST-CODE"
# ownership of the files was given back
container_args = aws_container.client.api.create_container.call_args_list[1][1]
assert container_args["command"] == "chown 1234:5678 -R /root/tmp/test"
assert mocked_new_tab.call_args[0][0] == test_link
# and the fallback method is printed
assert caplog.messages[0] == aws_container.FALLBACK_LINK_MSG.format(link=test_link)
21 changes: 11 additions & 10 deletions tests/test_containers/test_kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ def test_start_shell(kubectl_container):
assert container_args["entrypoint"] == ""

# make sure we are pointing to the AWS credentials
assert container_args["environment"]["AWS_CONFIG_FILE"] == "/root/tmp/test/config"
assert container_args["environment"]["AWS_SHARED_CREDENTIALS_FILE"] == "/root/tmp/test/credentials"
assert container_args["environment"]["AWS_CONFIG_FILE"] == "/home/leverage/tmp/test/config"
assert container_args["environment"]["AWS_SHARED_CREDENTIALS_FILE"] == "/home/leverage/tmp/test/credentials"

# make sure we mounted the .kube config folder
assert next(m for m in container_args["host_config"]["Mounts"] if m["Target"] == "/root/.kube")
print(container_args["host_config"])
assert next(m for m in container_args["host_config"]["Mounts"] if m["Target"] == "/home/leverage/.kube")

# and the aws config folder
assert next(m for m in container_args["host_config"]["Mounts"] if m["Target"] == "/root/tmp/test")
assert next(m for m in container_args["host_config"]["Mounts"] if m["Target"] == "/home/leverage/tmp/test")


# don't rely on the filesystem
Expand All @@ -75,7 +76,7 @@ def test_configure(kubectl_container, fake_os_user):
with patch.object(kubectl_container, "_start", return_value=0) as mock_start:
kubectl_container.configure()

assert mock_start.call_args[0][0] == f'bash -c "{AWS_EKS_UPDATE_KUBECONFIG} && chown 1234:5678 /root/.kube/config"'
assert mock_start.call_args[0][0] == AWS_EKS_UPDATE_KUBECONFIG


#####################
Expand All @@ -96,11 +97,11 @@ def test_start_shell_mfa(kubectl_container):

# we want a shell, so -> /bin/bash with no entrypoint
assert container_args["command"] == "/bin/bash"
assert container_args["entrypoint"] == "/root/scripts/aws-mfa/aws-mfa-entrypoint.sh -- "
assert container_args["entrypoint"] == "/opt/scripts/aws-mfa/aws-mfa-entrypoint.sh -- "

# make sure we are pointing to the right AWS credentials: /.aws/ folder for MFA
assert container_args["environment"]["AWS_CONFIG_FILE"] == "/root/.aws/test/config"
assert container_args["environment"]["AWS_SHARED_CREDENTIALS_FILE"] == "/root/.aws/test/credentials"
assert container_args["environment"]["AWS_CONFIG_FILE"] == "/home/leverage/.aws/test/config"
assert container_args["environment"]["AWS_SHARED_CREDENTIALS_FILE"] == "/home/leverage/.aws/test/credentials"


@patch("leverage.container.refresh_layer_credentials")
Expand All @@ -118,5 +119,5 @@ def test_start_shell_sso(mock_refresh, kubectl_container):
assert mock_refresh.called_once

# make sure we are pointing to the right AWS credentials: /tmp/ folder for SSO
assert container_args["environment"]["AWS_CONFIG_FILE"] == "/root/tmp/test/config"
assert container_args["environment"]["AWS_SHARED_CREDENTIALS_FILE"] == "/root/tmp/test/credentials"
assert container_args["environment"]["AWS_CONFIG_FILE"] == "/home/leverage/tmp/test/config"
assert container_args["environment"]["AWS_SHARED_CREDENTIALS_FILE"] == "/home/leverage/tmp/test/credentials"
8 changes: 0 additions & 8 deletions tests/test_containers/test_leverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ def leverage_container(muted_click_context):
return container_fixture_factory(LeverageContainer)


def test_change_ownership_cmd(leverage_container, fake_os_user):
assert leverage_container.change_ownership_cmd("/tmp/", recursive=True) == "chown 1234:5678 -R /tmp/"


def test_change_ownership_non_recursive_cmd(leverage_container, fake_os_user):
assert leverage_container.change_ownership_cmd("/tmp/file.txt", recursive=False) == "chown 1234:5678 /tmp/file.txt"


def test_mounts(muted_click_context):
container = container_fixture_factory(
LeverageContainer, mounts=(("/usr/bin", "/usr/bin"), ("/tmp/file.txt", "/tmp/file.txt"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_containers/test_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_auth_method_mfa_enabled(terraform_container):
terraform_container.sso_enabled = False
terraform_container.mfa_enabled = True

assert terraform_container.auth_method() == "/root/scripts/aws-mfa/aws-mfa-entrypoint.sh -- "
assert terraform_container.auth_method() == "/opt/scripts/aws-mfa/aws-mfa-entrypoint.sh -- "


def test_auth_method_else(terraform_container):
Expand Down

0 comments on commit 5e5b746

Please sign in to comment.