Refactor node ID handling, use check digits (fixes #269)
New node ID:s contain four Luhn check digits and are grouped differently. Code uses NodeID type instead of string, so it's formatted homogenously everywhere.
This commit is contained in:
@@ -4,28 +4,35 @@
|
||||
|
||||
package cid
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/calmh/syncthing/protocol"
|
||||
)
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
m := NewMap()
|
||||
|
||||
if i := m.Get("foo"); i != 1 {
|
||||
fooID := protocol.NewNodeID([]byte("foo"))
|
||||
barID := protocol.NewNodeID([]byte("bar"))
|
||||
|
||||
if i := m.Get(fooID); i != 1 {
|
||||
t.Errorf("Unexpected id %d != 1", i)
|
||||
}
|
||||
if i := m.Get("bar"); i != 2 {
|
||||
if i := m.Get(barID); i != 2 {
|
||||
t.Errorf("Unexpected id %d != 2", i)
|
||||
}
|
||||
if i := m.Get("foo"); i != 1 {
|
||||
if i := m.Get(fooID); i != 1 {
|
||||
t.Errorf("Unexpected id %d != 1", i)
|
||||
}
|
||||
if i := m.Get("bar"); i != 2 {
|
||||
if i := m.Get(barID); i != 2 {
|
||||
t.Errorf("Unexpected id %d != 2", i)
|
||||
}
|
||||
|
||||
if LocalID != 0 {
|
||||
t.Error("LocalID should be 0")
|
||||
}
|
||||
if i := m.Get(LocalName); i != LocalID {
|
||||
t.Errorf("Unexpected id %d != %c", i, LocalID)
|
||||
if i := m.Get(LocalNodeID); i != LocalID {
|
||||
t.Errorf("Unexpected id %d != %d", i, LocalID)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user