Skip to content

Commit a8b3055

Browse files
authored
Merge pull request #5 from proxymesh/feature/test-verbose-flag
Add -v/--verbose flag to test harness
2 parents 6de0c20 + 4942fda commit a8b3055

1 file changed

Lines changed: 37 additions & 9 deletions

File tree

test_proxy_headers.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@
1616
SEND_PROXY_VALUE - Header value to send to proxy (optional)
1717
1818
Usage:
19-
python test_proxy_headers.py [module1] [module2] ...
19+
python test_proxy_headers.py [-v] [module1] [module2] ...
2020
2121
# Test all modules
2222
python test_proxy_headers.py
2323
2424
# Test specific modules
2525
python test_proxy_headers.py requests httpx
2626
27+
# Verbose mode - show header values
28+
python test_proxy_headers.py -v
29+
2730
# With custom response header to check
2831
PROXY_HEADER=X-Custom-Header python test_proxy_headers.py
2932
3033
# Send a custom header to the proxy
3134
SEND_PROXY_HEADER=X-ProxyMesh-Country SEND_PROXY_VALUE=US python test_proxy_headers.py
3235
36+
Options:
37+
-v, --verbose Show proxy header values in results
38+
-l, --list List available modules
39+
-h, --help Show this help message
40+
3341
Exit codes:
3442
0 - All tests passed
3543
1 - One or more tests failed
@@ -101,11 +109,18 @@ class TestResult:
101109
error: Optional[str] = None
102110
response_status: Optional[int] = None
103111

104-
def __str__(self) -> str:
112+
def format(self, verbose: bool = False) -> str:
113+
"""Format the result for display."""
105114
if self.success:
106-
return f"[PASS] {self.module_name}: {self.header_value}"
115+
if verbose and self.header_value:
116+
return f"[PASS] {self.module_name}: {self.header_value}"
117+
else:
118+
return f"[PASS] {self.module_name}"
107119
else:
108120
return f"[FAIL] {self.module_name}: {self.error}"
121+
122+
def __str__(self) -> str:
123+
return self.format(verbose=False)
109124

110125

111126
# =============================================================================
@@ -473,12 +488,13 @@ def _mask_password(url: str) -> str:
473488
return url
474489

475490

476-
def print_results(results: List[TestResult]) -> bool:
491+
def print_results(results: List[TestResult], verbose: bool = False) -> bool:
477492
"""
478493
Print test results summary.
479494
480495
Args:
481496
results: List of test results
497+
verbose: If True, show header values in results
482498
483499
Returns:
484500
True if all tests passed, False otherwise
@@ -491,7 +507,7 @@ def print_results(results: List[TestResult]) -> bool:
491507
failed = 0
492508

493509
for result in results:
494-
print(result)
510+
print(result.format(verbose=verbose))
495511
if result.success:
496512
passed += 1
497513
else:
@@ -511,21 +527,33 @@ def print_results(results: List[TestResult]) -> bool:
511527
def main():
512528
"""Main entry point."""
513529
# Parse command line arguments
514-
test_names = sys.argv[1:] if len(sys.argv) > 1 else None
530+
args = sys.argv[1:] if len(sys.argv) > 1 else []
531+
532+
# Check for verbose flag
533+
verbose = False
534+
if '-v' in args:
535+
verbose = True
536+
args.remove('-v')
537+
if '--verbose' in args:
538+
verbose = True
539+
args.remove('--verbose')
515540

516541
# Handle --help
517-
if test_names and test_names[0] in ['--help', '-h']:
542+
if '--help' in args or '-h' in args:
518543
print(__doc__)
519544
print(f"\nAvailable modules: {', '.join(list_available_tests())}")
520545
sys.exit(0)
521546

522547
# Handle --list
523-
if test_names and test_names[0] in ['--list', '-l']:
548+
if '--list' in args or '-l' in args:
524549
print("Available modules:")
525550
for name in list_available_tests():
526551
print(f" - {name}")
527552
sys.exit(0)
528553

554+
# Remaining args are module names
555+
test_names = args if args else None
556+
529557
try:
530558
config = TestConfig.from_env()
531559
except EnvironmentError as e:
@@ -538,7 +566,7 @@ def main():
538566

539567
try:
540568
results = run_tests(test_names, config)
541-
all_passed = print_results(results)
569+
all_passed = print_results(results, verbose=verbose)
542570
sys.exit(0 if all_passed else 1)
543571
except KeyboardInterrupt:
544572
print("\nInterrupted.")

0 commit comments

Comments
 (0)