diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-07 12:20:02 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-07 12:20:02 +0100 |
commit | 70d0ad3c9f37e44a9504a0d7f66e412a3f3bba6f (patch) | |
tree | 623815a975541ebba1fba8208bd2b3e984ceb9d4 /module/ri-engine/src/test | |
parent | ede2372547db659e7b0e9cfd3b531ff542018229 (diff) | |
download | rules-sandbox-70d0ad3c9f37e44a9504a0d7f66e412a3f3bba6f.tar.gz rules-sandbox-70d0ad3c9f37e44a9504a0d7f66e412a3f3bba6f.tar.bz2 rules-sandbox-70d0ad3c9f37e44a9504a0d7f66e412a3f3bba6f.tar.xz rules-sandbox-70d0ad3c9f37e44a9504a0d7f66e412a3f3bba6f.zip |
More Wireguard.
Fixing broken myapps too.
Diffstat (limited to 'module/ri-engine/src/test')
-rw-r--r-- | module/ri-engine/src/test/java/io/trygvis/rules/network/IpCalcTest.java | 27 | ||||
-rw-r--r-- | module/ri-engine/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.java | 36 |
2 files changed, 36 insertions, 27 deletions
diff --git a/module/ri-engine/src/test/java/io/trygvis/rules/network/IpCalcTest.java b/module/ri-engine/src/test/java/io/trygvis/rules/network/IpCalcTest.java deleted file mode 100644 index e0642d6..0000000 --- a/module/ri-engine/src/test/java/io/trygvis/rules/network/IpCalcTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.trygvis.rules.network; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class IpCalcTest { - - @Test - public void basic() { - assertThrows(IllegalArgumentException.class, () -> IpCalc.cidr("192.168.1.1/24").addresses()); - assertEquals(256, IpCalc.cidr("192.168.1.0/24").addresses().size()); - assertEquals(128, IpCalc.cidr("192.168.1.128/25").addresses().size()); - } - - @ParameterizedTest - @ValueSource(strings = { - "192.168.1.0/24", - "192.168.1.128/25", - }) - public void testParsing(String s) { - assertEquals(s, IpCalc.cidr(s).toString()); - } -} diff --git a/module/ri-engine/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.java b/module/ri-engine/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.java new file mode 100644 index 0000000..0d9f33e --- /dev/null +++ b/module/ri-engine/src/test/java/io/trygvis/rules/network/Ipv4CidrTest.java @@ -0,0 +1,36 @@ +package io.trygvis.rules.network; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static io.trygvis.rules.network.Ipv4Cidr.parseCidr; +import static org.junit.jupiter.api.Assertions.*; + +class Ipv4CidrTest { + + @Test + public void basic() { + assertThrows(IllegalArgumentException.class, () -> parseCidr("192.168.1.1/24").addresses()); + assertEquals(256, parseCidr("192.168.1.0/24").addresses().size()); + assertEquals(128, parseCidr("192.168.1.128/25").addresses().size()); + } + + @ParameterizedTest + @ValueSource(strings = { + "192.168.1.0/24", + "192.168.1.128/25", + }) + public void testParsing(String s) { + assertEquals(s, parseCidr(s).toString()); + } + + @Test + public void partition() { + var children = parseCidr("192.168.1.0/24").partition(26); + assertEquals(1 << 2, children.size()); + for (var cidr : children) { + assertEquals(26, cidr.bits); + } + } +} |