Skip to content

Commit

Permalink
changed print_short in add_token.py (#4546)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrishtiKarkera authored Jun 27, 2024
1 parent dff3627 commit 0a11d61
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/wrappers/add_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def print_yaml(token, check):

def print_short(token, check):
default_ip, all_ips, port = get_network_info()

print(f"microk8s join {default_ip}:{port}/{token}/{check}")
for ip in all_ips:
print(f"microk8s join {ip}:{port}/{token}/{check}")
if ip != default_ip:
print(f"microk8s join {ip}:{port}/{token}/{check}")


if __name__ == "__main__":
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_addtoken.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from unittest import mock
from add_token import print_short


def test_single(capsys):
with mock.patch(
"add_token.get_network_info", return_value=["10.23.53.54", ["10.23.53.54"], "32"]
):
print_short("t", "c")
captured = capsys.readouterr()
output = captured.out.strip()
assert output == "microk8s join 10.23.53.54:32/t/c"


def test_multiple(capsys):
with mock.patch(
"add_token.get_network_info", return_value=["d_ip", ["ip1", "ip2", "d_ip"], "4"]
):
print_short("t", "c")
captured = capsys.readouterr()
all_outputs = captured.out.strip().split("\n")
assert all_outputs == [
"microk8s join d_ip:4/t/c",
"microk8s join ip1:4/t/c",
"microk8s join ip2:4/t/c",
]

0 comments on commit 0a11d61

Please sign in to comment.