github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/internal/tests/integration/net_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestNet_LookupIP(t *testing.T) {
     8  	inOutTest(t, `{{ net.LookupIP "localhost" }}`, "127.0.0.1")
     9  }
    10  
    11  func TestNet_CIDRHost(t *testing.T) {
    12  	inOutTestExperimental(t, `{{ net.ParsePrefix "10.12.127.0/20" | net.CIDRHost 16 }}`, "10.12.112.16")
    13  	inOutTestExperimental(t, `{{ "10.12.127.0/20" | net.CIDRHost 16 }}`, "10.12.112.16")
    14  	inOutTestExperimental(t, `{{ net.CIDRHost 268 "10.12.127.0/20" }}`, "10.12.113.12")
    15  	inOutTestExperimental(t, `{{ net.CIDRHost 34 "fd00:fd12:3456:7890:00a2::/72" }}`, "fd00:fd12:3456:7890::22")
    16  }
    17  
    18  func TestNet_CIDRNetmask(t *testing.T) {
    19  	inOutTestExperimental(t, `{{ "10.12.127.0/20" | net.CIDRNetmask }}`, "255.255.240.0")
    20  	inOutTestExperimental(t, `{{ net.CIDRNetmask "10.0.0.0/12" }}`, "255.240.0.0")
    21  	inOutTestExperimental(t, `{{ net.CIDRNetmask "fd00:fd12:3456:7890:00a2::/72" }}`, "ffff:ffff:ffff:ffff:ff00::")
    22  }
    23  
    24  func TestNet_CIDRSubnets(t *testing.T) {
    25  	inOutTestExperimental(t, `{{ index ("10.0.0.0/16" | net.CIDRSubnets 2) 1 }}`, "10.0.64.0/18")
    26  	inOutTestExperimental(t, `{{ range net.CIDRSubnets 2 "10.0.0.0/16" }}
    27  {{ . }}{{ end }}`, `
    28  10.0.0.0/18
    29  10.0.64.0/18
    30  10.0.128.0/18
    31  10.0.192.0/18`)
    32  }
    33  
    34  func TestNet_CIDRSubnetSizes(t *testing.T) {
    35  	inOutTestExperimental(t, `{{ index ("10.0.0.0/16" | net.CIDRSubnetSizes 1) 0 }}`, "10.0.0.0/17")
    36  	inOutTestExperimental(t, `{{ index ("10.1.0.0/16" | net.CIDRSubnetSizes 4 4 8 4) 1 }}`, "10.1.16.0/20")
    37  	inOutTestExperimental(t, `{{ range net.CIDRSubnetSizes 16 16 16 32 "fd00:fd12:3456:7890::/56" }}
    38  {{ . }}{{ end }}`, `
    39  fd00:fd12:3456:7800::/72
    40  fd00:fd12:3456:7800:100::/72
    41  fd00:fd12:3456:7800:200::/72
    42  fd00:fd12:3456:7800:300::/88`)
    43  }