Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
clinta committed Feb 13, 2018
1 parent 2c977c4 commit 25dda88
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
2 changes: 1 addition & 1 deletion iputil.go
Expand Up @@ -130,7 +130,7 @@ func IPDiff(ip, ip2 net.IP) int {
return ri * o
}

//IPDiff returns true if ip < ip2
//IPBefore returns true if ip < ip2
func IPBefore(ip, ip2 net.IP) bool {
ip, ip2 = makeNilZero(ip, ip2)
ip, ip2 = makeSameLength(ip, ip2)
Expand Down
40 changes: 40 additions & 0 deletions iputil6_test.go
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
)

// nolint dupl
func TestSubnetEqualSubnetTrue6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
_, net2, _ := net.ParseCIDR("fe80::/64")
Expand All @@ -14,6 +15,7 @@ func TestSubnetEqualSubnetTrue6(t *testing.T) {
}
}

// nolint dupl
func TestSubnetEqualSubnetFalseDifferentMask6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
_, net2, _ := net.ParseCIDR("fe80::/48")
Expand All @@ -22,6 +24,7 @@ func TestSubnetEqualSubnetFalseDifferentMask6(t *testing.T) {
}
}

// nolint dupl
func TestSubnetEqualSubnetFalseDifferentNet6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
_, net2, _ := net.ParseCIDR("fe80:1::/64")
Expand All @@ -30,6 +33,7 @@ func TestSubnetEqualSubnetFalseDifferentNet6(t *testing.T) {
}
}

// nolint dupl
func TestSubnetEqualSubnetTrueIpInNet6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
ip2, net2, _ := net.ParseCIDR("fe80::1/64")
Expand All @@ -39,62 +43,71 @@ func TestSubnetEqualSubnetTrueIpInNet6(t *testing.T) {
}
}

// nolint dupl
func TestSubnetEqualSubnetFalseN1Nil6(t *testing.T) {
_, net2, _ := net.ParseCIDR("fe80::/64")
if SubnetEqualSubnet(nil, net2) {
t.Errorf("Expected nil not equal %v", net2)
}
}

// nolint dupl
func TestSubnetEqualSubnetFalseN2Nil6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
if SubnetEqualSubnet(net1, nil) {
t.Errorf("Expected %v not equal nil", net1)
}
}

// nolint dupl
func TestSubnetEqualSubnetTrueN1NilN2Global6(t *testing.T) {
_, net2, _ := net.ParseCIDR("::/0")
if !SubnetEqualSubnet(nil, net2) {
t.Errorf("Expected nil equal %v", net2)
}
}

// nolint dupl
func TestSubnetEqualSubnetTrueN1GlobalN2Nil6(t *testing.T) {
_, net1, _ := net.ParseCIDR("::/0")
if !SubnetEqualSubnet(net1, nil) {
t.Errorf("Expected %v equal nil", net1)
}
}

// nolint dupl
func TestSubnetContainSubnetFalseN1Nil6(t *testing.T) {
_, net2, _ := net.ParseCIDR("fe80::/64")
if !SubnetContainsSubnet(nil, net2) {
t.Errorf("Expected nil contains %v", net2)
}
}

// nolint dupl
func TestSubnetContainSubnetFalseN2Nil6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
if SubnetContainsSubnet(net1, nil) {
t.Errorf("Expected %v not contains nil", net1)
}
}

// nolint dupl
func TestSubnetContainSubnetTrueN1NilN2Global6(t *testing.T) {
_, net2, _ := net.ParseCIDR("::/0")
if !SubnetContainsSubnet(nil, net2) {
t.Errorf("Expected nil contains %v", net2)
}
}

// nolint dupl
func TestSubnetContainSubnetTrueN1GlobalN2Nil6(t *testing.T) {
_, net1, _ := net.ParseCIDR("::/0")
if !SubnetContainsSubnet(net1, nil) {
t.Errorf("Expected %v contains nil", net1)
}
}

// nolint dupl
func TestSubnetContainSubnetTrueEqual6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
_, net2, _ := net.ParseCIDR("fe80::/64")
Expand All @@ -103,6 +116,7 @@ func TestSubnetContainSubnetTrueEqual6(t *testing.T) {
}
}

// nolint dupl
func TestSubnetContainSubnetTrueSmaller6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/48")
_, net2, _ := net.ParseCIDR("fe80::/64")
Expand All @@ -111,6 +125,7 @@ func TestSubnetContainSubnetTrueSmaller6(t *testing.T) {
}
}

// nolint dupl
func TestSubnetContainSubnetTrueSmallerDiff6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/48")
_, net2, _ := net.ParseCIDR("fe80:0:0:1::/64")
Expand All @@ -119,6 +134,7 @@ func TestSubnetContainSubnetTrueSmallerDiff6(t *testing.T) {
}
}

// nolint dupl
func TestSubnetContainSubnetFalseLarger6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
_, net2, _ := net.ParseCIDR("fe80::/48")
Expand All @@ -127,6 +143,7 @@ func TestSubnetContainSubnetFalseLarger6(t *testing.T) {
}
}

// nolint dupl
func TestSubnetContainSubnetFalseDifferent6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
_, net2, _ := net.ParseCIDR("fe80:1::/64")
Expand All @@ -135,6 +152,7 @@ func TestSubnetContainSubnetFalseDifferent6(t *testing.T) {
}
}

// nolint dupl
func TestLastAddr6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
lr := net.ParseIP("fe80::ffff:ffff:ffff:ffff")
Expand All @@ -143,6 +161,7 @@ func TestLastAddr6(t *testing.T) {
}
}

// nolint dupl
func TestFirstAddr6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::55/64")
lr := net.ParseIP("fe80::")
Expand All @@ -151,6 +170,7 @@ func TestFirstAddr6(t *testing.T) {
}
}

// nolint dupl
func TestNetworkID6(t *testing.T) {
ip1, net1, _ := net.ParseCIDR("fe80::55/64")
net1.IP = ip1
Expand All @@ -161,6 +181,7 @@ func TestNetworkID6(t *testing.T) {
}
}

// nolint dupl
func TestRandomAddr6(t *testing.T) {
_, net1, _ := net.ParseCIDR("fe80::/64")
for i := 1; i <= 10; i++ {
Expand All @@ -171,6 +192,7 @@ func TestRandomAddr6(t *testing.T) {
}
}

// nolint dupl
func TestIPAdd6(t *testing.T) {
ip := net.ParseIP("fe80::")
r := net.ParseIP("fe80::1")
Expand All @@ -179,6 +201,7 @@ func TestIPAdd6(t *testing.T) {
}
}

// nolint dupl
func TestIPAddCarryover6(t *testing.T) {
ip := net.ParseIP("fe80::ffff")
r := net.ParseIP("fe80::1:4")
Expand All @@ -187,6 +210,7 @@ func TestIPAddCarryover6(t *testing.T) {
}
}

// nolint dupl
func TestIPAddCarryover26(t *testing.T) {
ip := net.ParseIP("fe80::ffff:ffff")
r := net.ParseIP("fe80::1:0:4")
Expand All @@ -195,6 +219,7 @@ func TestIPAddCarryover26(t *testing.T) {
}
}

// nolint dupl
func TestIPSub6(t *testing.T) {
ip := net.ParseIP("fe80::5")
r := net.ParseIP("fe80::4")
Expand All @@ -203,6 +228,7 @@ func TestIPSub6(t *testing.T) {
}
}

// nolint dupl
func TestIPSubCarryover6(t *testing.T) {
ip := net.ParseIP("fe80::100")
r := net.ParseIP("fe80::fb")
Expand All @@ -212,6 +238,7 @@ func TestIPSubCarryover6(t *testing.T) {
}
}

// nolint dupl
func TestIPSubCarryover26(t *testing.T) {
ip := net.ParseIP("fe80::1:0")
r := net.ParseIP("fe80::fffb")
Expand All @@ -221,6 +248,7 @@ func TestIPSubCarryover26(t *testing.T) {
}
}

// nolint dupl
func TestIPBefore6(t *testing.T) {
ip := net.ParseIP("fe80::1")
ip2 := net.ParseIP("fe80::2")
Expand All @@ -230,6 +258,7 @@ func TestIPBefore6(t *testing.T) {
}
}

// nolint dupl
func TestIPNotBefore6(t *testing.T) {
ip := net.ParseIP("fe80::2")
ip2 := net.ParseIP("fe80::1")
Expand All @@ -239,6 +268,7 @@ func TestIPNotBefore6(t *testing.T) {
}
}

// nolint dupl
func TestIPBeforeEqual6(t *testing.T) {
ip := net.ParseIP("fe80::1")
ip2 := net.ParseIP("fe80::1")
Expand All @@ -248,6 +278,7 @@ func TestIPBeforeEqual6(t *testing.T) {
}
}

// nolint dupl
func TestIPBeforeNilFirst6(t *testing.T) {
ip2 := net.ParseIP("fe80::1")
ret := IPBefore(nil, ip2)
Expand All @@ -256,6 +287,7 @@ func TestIPBeforeNilFirst6(t *testing.T) {
}
}

// nolint dupl
func TestIPBeforeNilSecond6(t *testing.T) {
ip := net.ParseIP("fe80::1")
ret := IPBefore(ip, nil)
Expand All @@ -264,6 +296,7 @@ func TestIPBeforeNilSecond6(t *testing.T) {
}
}

// nolint dupl
func TestMakeSameLengthWithNil6(t *testing.T) {
ip := net.ParseIP("fe80::1")
nip, nip2 := makeNilZero(ip, nil)
Expand All @@ -274,6 +307,7 @@ func TestMakeSameLengthWithNil6(t *testing.T) {
}
}

// nolint dupl
func TestIPDiffNeg6(t *testing.T) {
ip := net.ParseIP("fe80::1")
ip2 := net.ParseIP("fe80::2")
Expand All @@ -283,6 +317,7 @@ func TestIPDiffNeg6(t *testing.T) {
}
}

// nolint dupl
func TestIPDiffPos6(t *testing.T) {
ip := net.ParseIP("fe80::2")
ip2 := net.ParseIP("fe80::1")
Expand All @@ -292,6 +327,7 @@ func TestIPDiffPos6(t *testing.T) {
}
}

// nolint dupl
func TestIPDiffEq6(t *testing.T) {
ip := net.ParseIP("fe80::1")
ip2 := net.ParseIP("fe80::1")
Expand All @@ -301,6 +337,7 @@ func TestIPDiffEq6(t *testing.T) {
}
}

// nolint dupl
func TestRandomAddrWithExclude6(t *testing.T) {
_, sn, _ := net.ParseCIDR("fe80::/120")
ip := RandAddrWithExclude(sn, 0, 0)
Expand All @@ -309,6 +346,7 @@ func TestRandomAddrWithExclude6(t *testing.T) {
}
}

// nolint dupl
func TestRandomAddrWithBadExcludeFirst6(t *testing.T) {
_, sn, _ := net.ParseCIDR("fe80::/120")
ip := RandAddrWithExclude(sn, 300, 0)
Expand All @@ -317,6 +355,7 @@ func TestRandomAddrWithBadExcludeFirst6(t *testing.T) {
}
}

// nolint dupl
func TestRandomAddrWithBadExcludeSecond6(t *testing.T) {
_, sn, _ := net.ParseCIDR("fe80::/120")
ip := RandAddrWithExclude(sn, 0, 300)
Expand All @@ -325,6 +364,7 @@ func TestRandomAddrWithBadExcludeSecond6(t *testing.T) {
}
}

// nolint dupl
func TestRandomAddrWithBadExcludeBoth6(t *testing.T) {
_, sn, _ := net.ParseCIDR("fe80::/120")
ip := RandAddrWithExclude(sn, 150, 150)
Expand Down

0 comments on commit 25dda88

Please sign in to comment.