Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-cidranger
Commits
3e90dcc8
Commit
3e90dcc8
authored
Feb 04, 2018
by
Yulin Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move network test
parent
bc6ed106
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
27 deletions
+27
-27
net/ip_test.go
net/ip_test.go
+27
-27
No files found.
net/ip_test.go
View file @
3e90dcc8
...
...
@@ -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
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment