...

Source file src/golang.conradwood.net/tests/utils/ip_tests.go

Documentation: golang.conradwood.net/tests/utils

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"golang.conradwood.net/go-easyops/utils"
     8  )
     9  
    10  func TestIPs() {
    11  	check_ip_private("192.168.1.1:5000", true)
    12  	check_ip_private("192.168.1.0/24", true)
    13  	check_ip_private("8.8.8.8/32", false)
    14  	check_ip_private("8.8.8.8/24", false)
    15  	check_ip_private("fe80::9e6b:ff:fe10:52c5/64", true)
    16  	check_ip_private("::1/128", true)
    17  	check_ip_private("2a00:1450:4009:823::2004", false)
    18  	check_ip_private("2a00:1450:4009:823::2004/64", false)
    19  	check_ip_private("[2a00:1450:4009:823::2004]:5000", false)
    20  }
    21  func check_ip_private(ip string, expected bool) {
    22  	fmt.Printf("Checking ip \"%s\"\n", ip)
    23  	b, err := utils.IsPrivateIP(ip)
    24  	utils.Bail(fmt.Sprintf("could not parse \"%s\"", ip), err)
    25  	if b != expected {
    26  		fmt.Printf("Expected private==%v for ip \"%s\" but result is %v", expected, ip, b)
    27  		os.Exit(10)
    28  	}
    29  }
    30  

View as plain text