mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 18:19:57 +00:00
TUN-4049: Add component tests to assert logging behavior when running from terminal
This commit is contained in:

committed by
Chung Ting Huang

parent
d22b374208
commit
f23e33c082
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
from util import start_cloudflared
|
||||
|
||||
|
||||
class TestConfig:
|
||||
# tmp_path is a fixture provides a temporary directory unique to the test invocation
|
||||
def test_validate_ingress_rules(self, tmp_path, component_tests_config):
|
||||
@@ -32,23 +33,25 @@ class TestConfig:
|
||||
}
|
||||
component_tests_config = component_tests_config(extra_config)
|
||||
validate_args = ["ingress", "validate"]
|
||||
pre_args = ["tunnel"]
|
||||
validate = start_cloudflared(tmp_path, component_tests_config, validate_args, pre_args)
|
||||
assert validate.returncode == 0, "failed to validate ingress" + validate.stderr.decode("utf-8")
|
||||
|
||||
self.match_rule(tmp_path, component_tests_config, "http://example.com/index.html", 1)
|
||||
self.match_rule(tmp_path, component_tests_config, "https://example.com/index.html", 1)
|
||||
self.match_rule(tmp_path, component_tests_config, "https://api.example.com/login", 2)
|
||||
self.match_rule(tmp_path, component_tests_config, "https://wss.example.com", 3)
|
||||
self.match_rule(tmp_path, component_tests_config, "https://ssh.example.com", 4)
|
||||
self.match_rule(tmp_path, component_tests_config, "https://api.example.com", 5)
|
||||
_ = start_cloudflared(tmp_path, component_tests_config, validate_args)
|
||||
|
||||
self.match_rule(tmp_path, component_tests_config,
|
||||
"http://example.com/index.html", 1)
|
||||
self.match_rule(tmp_path, component_tests_config,
|
||||
"https://example.com/index.html", 1)
|
||||
self.match_rule(tmp_path, component_tests_config,
|
||||
"https://api.example.com/login", 2)
|
||||
self.match_rule(tmp_path, component_tests_config,
|
||||
"https://wss.example.com", 3)
|
||||
self.match_rule(tmp_path, component_tests_config,
|
||||
"https://ssh.example.com", 4)
|
||||
self.match_rule(tmp_path, component_tests_config,
|
||||
"https://api.example.com", 5)
|
||||
|
||||
# This is used to check that the command tunnel ingress url <url> matches rule number <rule_num>. Note that rule number uses 1-based indexing
|
||||
|
||||
def match_rule(self, tmp_path, component_tests_config, url, rule_num):
|
||||
args = ["ingress", "rule", url]
|
||||
pre_args = ["tunnel"]
|
||||
match_rule = start_cloudflared(tmp_path, component_tests_config, args, pre_args)
|
||||
match_rule = start_cloudflared(tmp_path, component_tests_config, args)
|
||||
|
||||
assert match_rule.returncode == 0, "failed to check rule" + match_rule.stderr.decode("utf-8")
|
||||
assert f"Matched rule #{rule_num}" .encode() in match_rule.stdout
|
||||
assert f"Matched rule #{rule_num}" .encode() in match_rule.stdout
|
||||
|
Reference in New Issue
Block a user