Skip to content
Snippets Groups Projects
Commit 9a2f84b2 authored by takt's avatar takt Committed by Daniel Czerwonk
Browse files

Fix pfx dedup and add tests (#233)

parent 5496009b
No related branches found
No related tags found
No related merge requests found
package net
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIPCache(t *testing.T) {
a := &IP{
higher: 100,
lower: 200,
isLegacy: false,
}
b := &IP{
higher: 100,
lower: 200,
isLegacy: false,
}
x := a.Dedup()
y := b.Dedup()
assert.Equal(t, true, x == y)
}
...@@ -26,7 +26,7 @@ func (p *Prefix) Dedup() *Prefix { ...@@ -26,7 +26,7 @@ func (p *Prefix) Dedup() *Prefix {
// Less compares prefixes for use in btree.Btree // Less compares prefixes for use in btree.Btree
func (p *Prefix) Less(other btree.Item) bool { func (p *Prefix) Less(other btree.Item) bool {
if uintptr(unsafe.Pointer(p)) < uintptr(unsafe.Pointer(other.(*Prefix))) { if uintptr(unsafe.Pointer(p.addr)) < uintptr(unsafe.Pointer(other.(*Prefix).addr)) {
return true return true
} }
......
package net
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPrefixCache(t *testing.T) {
a := &Prefix{
addr: &IP{
higher: 100,
lower: 200,
isLegacy: false,
},
pfxlen: 64,
}
b := &Prefix{
addr: &IP{
higher: 100,
lower: 200,
isLegacy: false,
},
pfxlen: 64,
}
a.addr = a.addr.Dedup()
b.addr = b.addr.Dedup()
x := a.Dedup()
y := b.Dedup()
assert.Equal(t, true, x == y)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment