Skip to content

Commit

Permalink
Move network test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yulin Chen committed Feb 4, 2018
1 parent bc6ed10 commit 3e90dcc
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions net/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,33 @@ func TestNetworkContainsVersionMismatch(t *testing.T) {
}
}

func TestNetworkCovers(t *testing.T) {
cases := []struct {
network string
covers string
result bool
name string
}{
{"10.0.0.0/24", "10.0.0.1/25", true, "contains"},
{"10.0.0.0/24", "11.0.0.1/25", false, "not contains"},
{"10.0.0.0/16", "10.0.0.0/15", false, "prefix false"},
{"10.0.0.0/15", "10.0.0.0/16", true, "prefix true"},
{"10.0.0.0/15", "10.0.0.0/15", true, "same"},
{"10::0/15", "10.0.0.0/15", false, "ip version mismatch"},
{"10::0/15", "10::0/16", true, "ipv6"},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
_, n, _ := net.ParseCIDR(tc.network)
network := NewNetwork(*n)
_, n, _ = net.ParseCIDR(tc.covers)
covers := NewNetwork(*n)
assert.Equal(t, tc.result, network.Covers(covers))
})
}
}

func TestNetworkLeastCommonBitPosition(t *testing.T) {
cases := []struct {
cidr1 string
Expand Down Expand Up @@ -412,33 +439,6 @@ func TestPreviousIP(t *testing.T) {
}
}

func TestNetworkCovers(t *testing.T) {
cases := []struct {
network string
covers string
result bool
name string
}{
{"10.0.0.0/24", "10.0.0.1/25", true, "contains"},
{"10.0.0.0/24", "11.0.0.1/25", false, "not contains"},
{"10.0.0.0/16", "10.0.0.0/15", false, "prefix false"},
{"10.0.0.0/15", "10.0.0.0/16", true, "prefix true"},
{"10.0.0.0/15", "10.0.0.0/15", true, "same"},
{"10::0/15", "10.0.0.0/15", false, "ip version mismatch"},
{"10::0/15", "10::0/16", true, "ipv6"},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
_, n, _ := net.ParseCIDR(tc.network)
network := NewNetwork(*n)
_, n, _ = net.ParseCIDR(tc.covers)
covers := NewNetwork(*n)
assert.Equal(t, tc.result, network.Covers(covers))
})
}
}

/*
*********************************
Benchmarking ip manipulations.
Expand Down

0 comments on commit 3e90dcc

Please sign in to comment.