Send correct Node IDs in cluster config message (fixes #707)

This commit is contained in:
Jakob Borg 2014-09-19 13:21:58 +02:00
parent bf909db3f9
commit b1a31d3b30
2 changed files with 71 additions and 0 deletions

View File

@ -951,6 +951,9 @@ func (m *Model) clusterConfig(node protocol.NodeID) protocol.ClusterConfigMessag
ID: repo,
}
for _, node := range m.repoNodes[repo] {
// NodeID is a value type, but with an underlying array. Copy it
// so we don't grab aliases to the same array later on in node[:]
node := node
// TODO: Set read only bit when relevant
cr.Nodes = append(cr.Nodes, protocol.Node{
ID: node[:],

View File

@ -301,3 +301,71 @@ func TestNodeRename(t *testing.T) {
t.Errorf("Node name got overwritten")
}
}
func TestClusterConfig(t *testing.T) {
cfg := config.New("test", node1)
cfg.Nodes = []config.NodeConfiguration{
{
NodeID: node1,
},
{
NodeID: node2,
},
}
cfg.Repositories = []config.RepositoryConfiguration{
{
ID: "repo1",
Nodes: []config.RepositoryNodeConfiguration{
{NodeID: node1},
{NodeID: node2},
},
},
{
ID: "repo2",
Nodes: []config.RepositoryNodeConfiguration{
{NodeID: node1},
{NodeID: node2},
},
},
}
db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel("/tmp", &cfg, "node", "syncthing", "dev", db)
m.AddRepo(cfg.Repositories[0])
m.AddRepo(cfg.Repositories[1])
cm := m.clusterConfig(node2)
if l := len(cm.Repositories); l != 2 {
t.Fatalf("Incorrect number of repos %d != 2", l)
}
r := cm.Repositories[0]
if r.ID != "repo1" {
t.Errorf("Incorrect repo %q != repo1", r.ID)
}
if l := len(r.Nodes); l != 2 {
t.Errorf("Incorrect number of nodes %d != 2", l)
}
if id := r.Nodes[0].ID; bytes.Compare(id, node1[:]) != 0 {
t.Errorf("Incorrect node ID %x != %x", id, node1)
}
if id := r.Nodes[1].ID; bytes.Compare(id, node2[:]) != 0 {
t.Errorf("Incorrect node ID %x != %x", id, node2)
}
r = cm.Repositories[1]
if r.ID != "repo2" {
t.Errorf("Incorrect repo %q != repo2", r.ID)
}
if l := len(r.Nodes); l != 2 {
t.Errorf("Incorrect number of nodes %d != 2", l)
}
if id := r.Nodes[0].ID; bytes.Compare(id, node1[:]) != 0 {
t.Errorf("Incorrect node ID %x != %x", id, node1)
}
if id := r.Nodes[1].ID; bytes.Compare(id, node2[:]) != 0 {
t.Errorf("Incorrect node ID %x != %x", id, node2)
}
}