-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
cidr
helpers to templating ctx (#1)
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from noir.templating import _cidr_host, _cidr_netmask, _cidr_subnet, _cidr_subnets | ||
|
||
|
||
def test_cidr_host(): | ||
assert _cidr_host("10.12.112.0/20", 16) == "10.12.112.16" | ||
assert _cidr_host("10.12.112.0/20", 268) == "10.12.113.12" | ||
assert _cidr_host("fd00:fd12:3456:7890:00a2::/72", 34) == "fd00:fd12:3456:7890::22" | ||
|
||
|
||
def test_cidr_netmask(): | ||
assert _cidr_netmask("172.16.0.0/12") == "255.240.0.0" | ||
|
||
|
||
def test_cidr_subnet(): | ||
assert _cidr_subnet("172.16.0.0/12", 4, 2) == "172.18.0.0/16" | ||
assert _cidr_subnet("10.1.2.0/24", 4, 15) == "10.1.2.240/28" | ||
assert _cidr_subnet("fd00:fd12:3456:7890::/56", 16, 162) == "fd00:fd12:3456:7800:a200::/72" | ||
|
||
|
||
def test_cidr_subnets(): | ||
assert set(_cidr_subnets("10.1.0.0/16", 4, 4, 8, 4)) == { | ||
"10.1.0.0/20", | ||
"10.1.16.0/20", | ||
"10.1.32.0/24", | ||
"10.1.48.0/20", | ||
} |