Skip to content

Commit f0bb4e7

Browse files
committed
test for binary file
1 parent 0718515 commit f0bb4e7

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

test/binary_test.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import os
5+
import tempfile
6+
import time
7+
from pathlib import Path
8+
9+
from test_base import TestBase
10+
11+
from warnet.k8s import get_default_namespace
12+
from warnet.process import run_command
13+
14+
15+
class BinaryTest(TestBase):
16+
TEST_STRING = "Hello, World!"
17+
18+
def __init__(self):
19+
super().__init__()
20+
self.network_dir = Path(os.path.dirname(__file__)) / "data" / "small_2_node"
21+
22+
def run_test(self):
23+
try:
24+
self.setup_network()
25+
self.test_generic_binary()
26+
finally:
27+
self.cleanup()
28+
29+
def setup_network(self):
30+
self.log.info("Setting up network")
31+
self.log.info(self.warnet(f"deploy {self.network_dir}"))
32+
self.wait_for_all_tanks_status(target="running")
33+
self.wait_for_all_edges()
34+
35+
def test_generic_binary(self):
36+
self.log.info("Launching binary")
37+
temp_file_content = f"""#!/usr/bin/env sh
38+
echo {self.TEST_STRING}"""
39+
40+
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".sh") as temp_file:
41+
temp_file.write(temp_file_content)
42+
temp_file_path = temp_file.name
43+
44+
os.chmod(temp_file_path, 0o755)
45+
self.warnet(f"run-binary {temp_file_path}")
46+
47+
# Get the commander pod name
48+
pods = run_command(f"kubectl get pods -n {get_default_namespace()} -o json")
49+
pods = json.loads(pods)
50+
pod_list = [item["metadata"]["name"] for item in pods["items"]]
51+
binary_pod = next((pod for pod in pod_list if pod.startswith("binary")), None)
52+
if binary_pod is None:
53+
raise ValueError("No pod found starting with 'binary'")
54+
self.log.info(f"Got pod: {binary_pod}")
55+
56+
def g_log():
57+
logs = self.warnet(f"logs {binary_pod}")
58+
return self.TEST_STRING in logs
59+
60+
time.sleep(5)
61+
self.wait_for_predicate(g_log, timeout=60, interval=5)
62+
63+
os.unlink(temp_file_path)
64+
65+
66+
if __name__ == "__main__":
67+
test = BinaryTest()
68+
test.run_test()

test/data/small_2_node/network.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
nodes:
2+
- name: tank-0000
3+
connect:
4+
- tank-0001
5+
- name: tank-0001
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
image:
2+
repository: bitcoindevproject/bitcoin
3+
pullPolicy: IfNotPresent
4+
tag: "27.0"

0 commit comments

Comments
 (0)