fix typo in main() and add random ip generation

This commit is contained in:
Damian Bednarczyk
2023-12-01 21:08:53 -06:00
parent d9714fb449
commit 54173cf672
3 changed files with 53 additions and 12 deletions

View File

@@ -0,0 +1,28 @@
package bot
import (
"net"
"testing"
)
func TestRandomIPFromSubnet(t *testing.T) {
subnets := []string{"34.100.182.96/28", "207.46.13.0/24", "2001:4860:4801:10::/64", "2001:4860:4801:c::/64"}
for _, subnet := range subnets {
t.Run(subnet, func(t *testing.T) {
_, ipnet, err := net.ParseCIDR(subnet)
if err != nil {
t.Error(err)
}
ip, err := randomIPFromSubnet(subnet)
if err != nil {
t.Error(err)
}
if !ipnet.Contains(ip) {
t.Fail()
}
})
}
}