Update test scripts to support environment variable processing and validate responses for different data types.
Some checks failed
Docker Build Test / build (3.11) (push) Successful in 9s
Docker Build Test / build (3.13) (push) Successful in 10s
Docker Build Test / build (3.12) (push) Successful in 39s
Docker Build Test / build (3.10) (push) Successful in 42s
Docker Build Test / build (3.9) (push) Successful in 38s
Build and Publish Docker Image / build (push) Failing after 9m35s
Some checks failed
Docker Build Test / build (3.11) (push) Successful in 9s
Docker Build Test / build (3.13) (push) Successful in 10s
Docker Build Test / build (3.12) (push) Successful in 39s
Docker Build Test / build (3.10) (push) Successful in 42s
Docker Build Test / build (3.9) (push) Successful in 38s
Build and Publish Docker Image / build (push) Failing after 9m35s
This commit is contained in:
28
tests/run_tests.sh
Normal file → Executable file
28
tests/run_tests.sh
Normal file → Executable file
@@ -9,11 +9,33 @@ rm -rf config node-config pages files node.log
|
|||||||
mkdir -p config node-config pages files
|
mkdir -p config node-config pages files
|
||||||
|
|
||||||
# Create a sample page and a test file
|
# Create a sample page and a test file
|
||||||
cat > pages/index.mu << EOF
|
cat > pages/index.mu << 'EOF'
|
||||||
>Test Page
|
#!/usr/bin/env python3
|
||||||
This is a test page.
|
import os
|
||||||
|
|
||||||
|
print("`F0f0`_`Test Page`_")
|
||||||
|
print("This is a test page with environment variable support.")
|
||||||
|
print()
|
||||||
|
|
||||||
|
print("`F0f0`_`Environment Variables`_")
|
||||||
|
params = []
|
||||||
|
for key, value in os.environ.items():
|
||||||
|
if key.startswith(('field_', 'var_')):
|
||||||
|
params.append(f"- `Faaa`{key}`f: `F0f0`{value}`f")
|
||||||
|
|
||||||
|
if params:
|
||||||
|
print("\n".join(params))
|
||||||
|
else:
|
||||||
|
print("- No parameters received")
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("`F0f0`_`Remote Identity`_")
|
||||||
|
remote_id = os.environ.get('remote_identity', '33aff86b736acd47dca07e84630fd192') # Mock for testing
|
||||||
|
print(f"`Faaa`{remote_id}`f")
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
chmod +x pages/index.mu
|
||||||
|
|
||||||
cat > files/text.txt << EOF
|
cat > files/text.txt << EOF
|
||||||
This is a test file.
|
This is a test file.
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -36,6 +36,14 @@ global_link = RNS.Link(destination)
|
|||||||
responses = {}
|
responses = {}
|
||||||
done_event = threading.Event()
|
done_event = threading.Event()
|
||||||
|
|
||||||
|
# Test data for environment variables
|
||||||
|
test_data_dict = {
|
||||||
|
'var_field_test': 'dictionary_value',
|
||||||
|
'var_field_message': 'hello_world',
|
||||||
|
'var_action': 'test_action'
|
||||||
|
}
|
||||||
|
test_data_bytes = b'field_bytes_test=bytes_value|field_bytes_message=test_bytes|action=bytes_action'
|
||||||
|
|
||||||
|
|
||||||
# Callback for page response
|
# Callback for page response
|
||||||
def on_page(response):
|
def on_page(response):
|
||||||
@@ -44,10 +52,37 @@ def on_page(response):
|
|||||||
text = data.decode("utf-8")
|
text = data.decode("utf-8")
|
||||||
else:
|
else:
|
||||||
text = str(data)
|
text = str(data)
|
||||||
print("Received page:")
|
print("Received page (no data):")
|
||||||
print(text)
|
print(text)
|
||||||
responses["page"] = text
|
responses["page"] = text
|
||||||
if "file" in responses:
|
check_responses()
|
||||||
|
|
||||||
|
# Callback for page response with dictionary data
|
||||||
|
def on_page_dict(response):
|
||||||
|
data = response.response
|
||||||
|
if isinstance(data, bytes):
|
||||||
|
text = data.decode("utf-8")
|
||||||
|
else:
|
||||||
|
text = str(data)
|
||||||
|
print("Received page (dict data):")
|
||||||
|
print(text)
|
||||||
|
responses["page_dict"] = text
|
||||||
|
check_responses()
|
||||||
|
|
||||||
|
# Callback for page response with bytes data
|
||||||
|
def on_page_bytes(response):
|
||||||
|
data = response.response
|
||||||
|
if isinstance(data, bytes):
|
||||||
|
text = data.decode("utf-8")
|
||||||
|
else:
|
||||||
|
text = str(data)
|
||||||
|
print("Received page (bytes data):")
|
||||||
|
print(text)
|
||||||
|
responses["page_bytes"] = text
|
||||||
|
check_responses()
|
||||||
|
|
||||||
|
def check_responses():
|
||||||
|
if "page" in responses and "page_dict" in responses and "page_bytes" in responses and "file" in responses:
|
||||||
done_event.set()
|
done_event.set()
|
||||||
|
|
||||||
|
|
||||||
@@ -78,13 +113,18 @@ def on_file(response):
|
|||||||
else:
|
else:
|
||||||
print("Received file (unhandled format):", data)
|
print("Received file (unhandled format):", data)
|
||||||
responses["file"] = str(data)
|
responses["file"] = str(data)
|
||||||
if "page" in responses:
|
check_responses()
|
||||||
done_event.set()
|
|
||||||
|
|
||||||
|
|
||||||
# Request the page and file once the link is established
|
# Request the pages and file once the link is established
|
||||||
def on_link_established(link):
|
def on_link_established(link):
|
||||||
|
# Test page without data
|
||||||
link.request("/page/index.mu", None, response_callback=on_page)
|
link.request("/page/index.mu", None, response_callback=on_page)
|
||||||
|
# Test page with dictionary data (simulates MeshChat)
|
||||||
|
link.request("/page/index.mu", test_data_dict, response_callback=on_page_dict)
|
||||||
|
# Test page with bytes data (URL-encoded style)
|
||||||
|
link.request("/page/index.mu", test_data_bytes, response_callback=on_page_bytes)
|
||||||
|
# Test file serving
|
||||||
link.request("/file/text.txt", None, response_callback=on_file)
|
link.request("/file/text.txt", None, response_callback=on_file)
|
||||||
|
|
||||||
|
|
||||||
@@ -97,8 +137,63 @@ if not done_event.wait(timeout=30):
|
|||||||
print("Test timed out.", file=sys.stderr)
|
print("Test timed out.", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if responses.get("page") and responses.get("file"):
|
# Validate test results
|
||||||
print("Tests passed!")
|
def validate_test_results():
|
||||||
|
"""Validate that all responses contain expected content"""
|
||||||
|
|
||||||
|
# Check basic page response (no data)
|
||||||
|
if "page" not in responses:
|
||||||
|
print("ERROR: No basic page response received", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
page_content = responses["page"]
|
||||||
|
if "No parameters received" not in page_content:
|
||||||
|
print("ERROR: Basic page should show 'No parameters received'", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
if "33aff86b736acd47dca07e84630fd192" not in page_content:
|
||||||
|
print("ERROR: Basic page should show mock remote identity", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Check page with dictionary data
|
||||||
|
if "page_dict" not in responses:
|
||||||
|
print("ERROR: No dictionary data page response received", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
dict_content = responses["page_dict"]
|
||||||
|
if "var_field_test" not in dict_content or "dictionary_value" not in dict_content:
|
||||||
|
print("ERROR: Dictionary data page should contain processed environment variables", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
if "33aff86b736acd47dca07e84630fd192" not in dict_content:
|
||||||
|
print("ERROR: Dictionary data page should show mock remote identity", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Check page with bytes data
|
||||||
|
if "page_bytes" not in responses:
|
||||||
|
print("ERROR: No bytes data page response received", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
bytes_content = responses["page_bytes"]
|
||||||
|
if "field_bytes_test" not in bytes_content or "bytes_value" not in bytes_content:
|
||||||
|
print("ERROR: Bytes data page should contain processed environment variables", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
if "33aff86b736acd47dca07e84630fd192" not in bytes_content:
|
||||||
|
print("ERROR: Bytes data page should show mock remote identity", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Check file response
|
||||||
|
if "file" not in responses:
|
||||||
|
print("ERROR: No file response received", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
file_content = responses["file"]
|
||||||
|
if "This is a test file" not in file_content:
|
||||||
|
print("ERROR: File content doesn't match expected content", file=sys.stderr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
if validate_test_results():
|
||||||
|
print("All tests passed! Environment variable processing works correctly.")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
print("Tests failed.", file=sys.stderr)
|
print("Tests failed.", file=sys.stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user