Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bio-rd
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
bio-rd
Commits
c8428439
Commit
c8428439
authored
6 years ago
by
Oliver Herms
Browse files
Options
Downloads
Patches
Plain Diff
Adding test
parent
b54ca9e1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
routingtable/adjRIBOut/path_id_manager.go
+1
-0
1 addition, 0 deletions
routingtable/adjRIBOut/path_id_manager.go
routingtable/adjRIBOut/path_id_manager_test.go
+231
-0
231 additions, 0 deletions
routingtable/adjRIBOut/path_id_manager_test.go
with
232 additions
and
0 deletions
routingtable/adjRIBOut/path_id_manager.go
+
1
−
0
View file @
c8428439
...
...
@@ -61,6 +61,7 @@ func (fm *pathIDManager) releasePath(p *route.Path) (uint32, error) {
delete
(
fm
.
ids
,
fm
.
idByPath
[
*
p
.
BGPPath
])
delete
(
fm
.
idByPath
,
*
p
.
BGPPath
)
}
fm
.
used
--
return
id
,
nil
}
This diff is collapsed.
Click to expand it.
routingtable/adjRIBOut/path_id_manager_test.go
0 → 100644
+
231
−
0
View file @
c8428439
package
adjRIBOut
import
(
"testing"
"github.com/bio-routing/bio-rd/route"
"github.com/stretchr/testify/assert"
)
func
TestAddPath
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
maxIDs
uint32
count
int
wantFail
bool
}{
{
name
:
"Out of path IDs"
,
maxIDs
:
10
,
count
:
11
,
wantFail
:
true
,
},
{
name
:
"Success"
,
maxIDs
:
10
,
count
:
10
,
wantFail
:
false
,
},
}
X
:
for
_
,
test
:=
range
tests
{
maxUint32
=
test
.
maxIDs
m
:=
newPathIDManager
()
for
i
:=
0
;
i
<
test
.
count
;
i
++
{
_
,
err
:=
m
.
addPath
(
&
route
.
Path
{
BGPPath
:
&
route
.
BGPPath
{
LocalPref
:
uint32
(
i
)}})
if
err
!=
nil
{
if
test
.
wantFail
{
continue
X
}
t
.
Errorf
(
"Unexpected failure for test %q: %v"
,
test
.
name
,
err
)
continue
X
}
}
if
test
.
wantFail
{
t
.
Errorf
(
"Unexpected success for test %q"
,
test
.
name
)
continue
}
}
}
func
TestReleasePath
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
pm
*
pathIDManager
release
*
route
.
Path
expected
*
pathIDManager
wantFail
bool
}{
{
name
:
"Release existent"
,
pm
:
&
pathIDManager
{
ids
:
map
[
uint32
]
uint64
{
0
:
1
,
1
:
1
,
2
:
1
,
},
idByPath
:
map
[
route
.
BGPPath
]
uint32
{
route
.
BGPPath
{
LocalPref
:
0
,
}
:
0
,
route
.
BGPPath
{
LocalPref
:
1
,
}
:
1
,
route
.
BGPPath
{
LocalPref
:
2
,
}
:
2
,
},
last
:
2
,
used
:
3
,
},
release
:
&
route
.
Path
{
BGPPath
:
&
route
.
BGPPath
{
LocalPref
:
2
,
}},
expected
:
&
pathIDManager
{
ids
:
map
[
uint32
]
uint64
{
0
:
1
,
1
:
1
,
},
idByPath
:
map
[
route
.
BGPPath
]
uint32
{
route
.
BGPPath
{
LocalPref
:
0
,
}
:
0
,
route
.
BGPPath
{
LocalPref
:
1
,
}
:
1
,
},
last
:
2
,
used
:
2
,
},
},
{
name
:
"Release non-existent"
,
pm
:
&
pathIDManager
{
ids
:
map
[
uint32
]
uint64
{
0
:
1
,
1
:
1
,
2
:
1
,
},
idByPath
:
map
[
route
.
BGPPath
]
uint32
{
route
.
BGPPath
{
LocalPref
:
0
,
}
:
0
,
route
.
BGPPath
{
LocalPref
:
1
,
}
:
1
,
route
.
BGPPath
{
LocalPref
:
2
,
}
:
2
,
},
last
:
2
,
used
:
3
,
},
release
:
&
route
.
Path
{
BGPPath
:
&
route
.
BGPPath
{
LocalPref
:
4
,
}},
expected
:
&
pathIDManager
{
ids
:
map
[
uint32
]
uint64
{
0
:
1
,
1
:
1
,
2
:
1
,
},
idByPath
:
map
[
route
.
BGPPath
]
uint32
{
route
.
BGPPath
{
LocalPref
:
0
,
}
:
0
,
route
.
BGPPath
{
LocalPref
:
1
,
}
:
1
,
route
.
BGPPath
{
LocalPref
:
2
,
}
:
2
,
},
last
:
2
,
used
:
3
,
},
wantFail
:
true
,
},
}
for
_
,
test
:=
range
tests
{
_
,
err
:=
test
.
pm
.
releasePath
(
test
.
release
)
if
err
!=
nil
{
if
test
.
wantFail
{
continue
}
t
.
Errorf
(
"Unexpected failure for test %q: %v"
,
test
.
name
,
err
)
continue
}
if
test
.
wantFail
{
t
.
Errorf
(
"Unexpected success for test %q"
,
test
.
name
)
continue
}
assert
.
Equalf
(
t
,
test
.
expected
,
test
.
pm
,
"%s"
,
test
.
name
)
}
}
/*func TestReleaseID(t *testing.T) {
tests := []struct {
name string
pm *pathIDManager
release uint32
expected *pathIDManager
}{
{
name: "Release existent",
pm: &pathIDManager{
ids: map[uint32]struct{}{
0: struct{}{},
1: struct{}{},
2: struct{}{},
},
last: 2,
used: 3,
},
release: 1,
expected: &pathIDManager{
ids: map[uint32]struct{}{
0: struct{}{},
2: struct{}{},
},
last: 2,
used: 2,
},
},
{
name: "Release non-existent",
pm: &pathIDManager{
ids: map[uint32]struct{}{
0: struct{}{},
1: struct{}{},
2: struct{}{},
},
last: 2,
used: 3,
},
release: 3,
expected: &pathIDManager{
ids: map[uint32]struct{}{
0: struct{}{},
1: struct{}{},
2: struct{}{},
},
last: 2,
used: 3,
},
},
}
for _, test := range tests {
test.pm.releaseID(test.release)
assert.Equalf(t, test.expected, test.pm, "%s", test.name)
}
}
*/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment