~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/azure/internal/iputils/iputils_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        )
48
48
}
49
49
 
 
50
func (*iputilsSuite) TestNthSubnetIP(c *gc.C) {
 
51
        assertNthSubnetIP(c, "10.0.0.0/8", 0, "10.0.0.4")
 
52
        assertNthSubnetIP(c, "10.0.0.0/8", 1, "10.0.0.5")
 
53
        assertNthSubnetIP(c, "10.0.0.0/29", 0, "10.0.0.4")
 
54
        assertNthSubnetIP(c, "10.0.0.0/29", 1, "10.0.0.5")
 
55
        assertNthSubnetIP(c, "10.0.0.0/29", 2, "10.0.0.6")
 
56
        assertNthSubnetIP(c, "10.0.0.0/29", 3, "") // all bits set, broadcast
 
57
        assertNthSubnetIP(c, "10.1.2.0/30", 0, "")
 
58
}
 
59
 
50
60
func assertNextSubnetIP(c *gc.C, ipnetString string, inuseStrings []string, expectedString string) {
51
61
        ipnet := parseIPNet(c, ipnetString)
52
62
        inuse := parseIPs(c, inuseStrings...)
62
72
        c.Assert(err, gc.ErrorMatches, expect)
63
73
}
64
74
 
 
75
func assertNthSubnetIP(c *gc.C, ipnetString string, n int, expectedString string) {
 
76
        ipnet := parseIPNet(c, ipnetString)
 
77
        ip := iputils.NthSubnetIP(ipnet, n)
 
78
        if expectedString == "" {
 
79
                c.Assert(ip, gc.IsNil)
 
80
        } else {
 
81
                c.Assert(ip, gc.NotNil)
 
82
                c.Assert(ip.String(), gc.Equals, expectedString)
 
83
        }
 
84
}
 
85
 
65
86
func parseIPs(c *gc.C, ipStrings ...string) []net.IP {
66
87
        ips := make([]net.IP, len(ipStrings))
67
88
        for i, ipString := range ipStrings {