Skip to content

Commit

Permalink
Unit test now covers sing-ruleset.
Browse files Browse the repository at this point in the history
  • Loading branch information
xkww3n committed Dec 2, 2023
1 parent 8fb4a06 commit 33553b4
Showing 1 changed file with 57 additions and 8 deletions.
65 changes: 57 additions & 8 deletions Tests/test_2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ def test_load_domain(self):
test_src_path = Path("./src/custom_ruleset/")
loaded_ruleset = ruleset.load(test_src_path / "domain.txt")
assert loaded_ruleset == ruleset.RuleSet("Domain",
[rule.Rule("DomainSuffix", "example.com"),
rule.Rule("DomainFull", "example.com")])
[rule.Rule("DomainSuffix", "example.com"),
rule.Rule("DomainFull", "example.com")])

def test_load_ipcidr(self):
test_src_path = Path("./src/custom_ruleset/")
loaded_ruleset = ruleset.load(test_src_path / "ipcidr.txt")
assert loaded_ruleset == ruleset.RuleSet("IPCIDR",
[rule.Rule("IPCIDR", "11.4.5.14"),
rule.Rule("IPCIDR6", "fc00:114::514")])
[rule.Rule("IPCIDR", "11.4.5.14"),
rule.Rule("IPCIDR6", "fc00:114::514")])

def test_load_combined(self):
test_src_path = Path("./src/custom_ruleset/")
loaded_ruleset = ruleset.load(test_src_path / "combined.txt")
assert loaded_ruleset == ruleset.RuleSet("Combined",
[rule.Rule("DomainFull", "example.com"),
rule.Rule("DomainSuffix", "example.com"),
rule.Rule("IPCIDR", "11.4.5.14"),
rule.Rule("IPCIDR6", "fc00:114::514")])
[rule.Rule("DomainFull", "example.com"),
rule.Rule("DomainSuffix", "example.com"),
rule.Rule("IPCIDR", "11.4.5.14"),
rule.Rule("IPCIDR6", "fc00:114::514")])

def test_patch(self):
test_src_patch = Path("./src/patch/")
Expand Down Expand Up @@ -89,6 +89,22 @@ def test_dump_domain(self):
assert f.read() == ("example.com\n"
"full:example.com\n")

assert (test_dist/"sing-ruleset"/"domain.json").exists()
with open(test_dist/"sing-ruleset"/"domain.json", mode="r") as f:
assert f.read() == ('{\n'
' "version": 1,\n'
' "rules": [\n'
' {\n'
' "domain_suffix": [\n'
' ".example.com"\n'
' ],\n'
' "domain": [\n'
' "example.com"\n'
' ]\n'
' }\n'
' ]\n'
'}')

def test_dump_ipcidr(self):
test_dist = Path("./dists/")
ruleset_ipcidr = ruleset.load(Path("./src/custom_ruleset/ipcidr.txt"))
Expand Down Expand Up @@ -118,6 +134,20 @@ def test_dump_ipcidr(self):
" - '11.4.5.14'\n"
" - 'fc00:114::514'\n")

assert (test_dist/"sing-ruleset"/"ipcidr.json").exists()
with open(test_dist/"sing-ruleset"/"ipcidr.json", mode="r") as f:
assert f.read() == ('{\n'
' "version": 1,\n'
' "rules": [\n'
' {\n'
' "ip_cidr": [\n'
' "11.4.5.14",\n'
' "fc00:114::514"\n'
' ]\n'
' }\n'
' ]\n'
'}')

def test_dump_combined(self):
test_dist = Path("./dists/")
ruleset_combined = ruleset.load(Path("./src/custom_ruleset/combined.txt"))
Expand All @@ -141,3 +171,22 @@ def test_dump_combined(self):
"DOMAIN-SUFFIX,example.com\n"
"IP-CIDR,11.4.5.14\n"
"IP-CIDR6,fc00:114::514\n")

assert (test_dist/"sing-ruleset"/"combined.json").exists()
with open(test_dist/"sing-ruleset"/"combined.json", mode="r") as f:
assert f.read() == ('{\n'
' "version": 1,\n'
' "rules": [\n'
' {\n'
' "domain": [\n'
' "example.com"\n'
' ],\n'
' "domain_suffix": [\n'
' ".example.com"\n'
' ],\n'
' "ip_cidr": [\n'
' "11.4.5.14"\n'
' ]\n'
' }\n'
' ]\n'
'}')

0 comments on commit 33553b4

Please sign in to comment.