1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

add a test for the case when peerId is different

This commit is contained in:
Anatolii Smolianinov 2024-09-17 11:42:16 +02:00
parent 4a9b28e822
commit 09a232f09a
No known key found for this signature in database
GPG key ID: 5E259D1D468B99F4

View file

@ -219,77 +219,78 @@ func newTestConf() *testConf {
}
func TestService_mergeCoordinatorAddrs(t *testing.T) {
confApp := Configuration{
Id: "test",
NetworkId: "testNetwork",
Nodes: []Node{
{
PeerId: "12D3KooWKLCajM89S8unbt3tgGbRLgmiWnFZT3adn9A5pQciBSLa",
Addresses: []string{"127.0.0.1:4830", "192.168.1.1:8833"},
Types: []NodeType{NodeTypeCoordinator},
},
{
PeerId: "12D3KooWKnXTtbveMDUFfeSqR5dt9a4JW66tZQXG7C7PdDh3vqGu",
Addresses: []string{"127.0.0.1:4730"},
Types: []NodeType{NodeTypeTree},
},
{
PeerId: "12D3KooWKgVN2kW8xw5Uvm2sLUnkeUNQYAvcWvF58maTzev7FjPi",
Addresses: []string{"127.0.0.1:4731"},
Types: []NodeType{NodeTypeTree},
},
{
PeerId: "12D3KooWCUPYuMnQhu9yREJgQyjcz8zWY83rZGmDLwb9YR6QkbZX",
Addresses: []string{"127.0.0.1:4732"},
Types: []NodeType{NodeTypeTree},
},
{
PeerId: "12D3KooWQxiZ5a7vcy4DTJa8Gy1eVUmwb5ojN4SrJC9Rjxzigw6C",
Addresses: []string{"127.0.0.1:4733"},
Types: []NodeType{NodeTypeFile},
},
},
CreationTime: time.Now(),
}
confStored := Configuration{
Id: "test",
NetworkId: "testNetwork",
Nodes: []Node{
{
PeerId: "12D3KooWKLCajM89S8unbt3tgGbRLgmiWnFZT3adn9A5pQciBSLa",
Addresses: []string{"127.0.0.1:4830"},
Types: []NodeType{NodeTypeCoordinator},
t.Run("coorditor nodes with different peerID added", func(t *testing.T) {
confApp := Configuration{
Id: "test",
NetworkId: "testNetwork",
Nodes: []Node{
{
PeerId: "12D3KooWKgVN2kW8xw5Uvm2sLUnkeUNQYAvcWvF58maTzev7FjPi",
Addresses: []string{"127.0.0.1:3030", "192.168.1.1:8833"},
Types: []NodeType{NodeTypeCoordinator},
},
},
{
PeerId: "12D3KooWKnXTtbveMDUFfeSqR5dt9a4JW66tZQXG7C7PdDh3vqGu",
Addresses: []string{"127.0.0.1:4730"},
Types: []NodeType{NodeTypeTree},
},
{
PeerId: "12D3KooWKgVN2kW8xw5Uvm2sLUnkeUNQYAvcWvF58maTzev7FjPi",
Addresses: []string{"127.0.0.1:4731"},
Types: []NodeType{NodeTypeTree},
},
{
PeerId: "12D3KooWCUPYuMnQhu9yREJgQyjcz8zWY83rZGmDLwb9YR6QkbZX",
Addresses: []string{"127.0.0.1:4732"},
Types: []NodeType{NodeTypeTree},
},
{
PeerId: "12D3KooWQxiZ5a7vcy4DTJa8Gy1eVUmwb5ojN4SrJC9Rjxzigw6C",
Addresses: []string{"127.0.0.1:4733"},
Types: []NodeType{NodeTypeFile},
},
},
CreationTime: time.Now(),
}
CreationTime: time.Now(),
}
confStored := Configuration{
Id: "test",
NetworkId: "testNetwork",
Nodes: []Node{
{
PeerId: "12D3KooWKLCajM89S8unbt3tgGbRLgmiWnFZT3adn9A5pQciBSLa",
Addresses: []string{"127.0.0.1:4830"},
Types: []NodeType{NodeTypeCoordinator},
},
},
CreationTime: time.Now(),
}
mergeCoordinatorAddrs(&confApp, &confStored)
assert.Equal(t, 2, len(confStored.Nodes))
assert.Equal(t, "127.0.0.1:3030", confStored.Nodes[1].Addresses[0])
assert.Equal(t, "192.168.1.1:8833", confStored.Nodes[1].Addresses[1])
assert.Equal(t, "12D3KooWKgVN2kW8xw5Uvm2sLUnkeUNQYAvcWvF58maTzev7FjPi", confStored.Nodes[1].PeerId)
})
t.Run("coorditor nodes with the same peerID have Addresses merged", func(t *testing.T) {
confApp := Configuration{
Id: "test",
NetworkId: "testNetwork",
Nodes: []Node{
{
PeerId: "12D3KooWKLCajM89S8unbt3tgGbRLgmiWnFZT3adn9A5pQciBSLa",
Addresses: []string{"127.0.0.1:4830", "192.168.1.1:8833"},
Types: []NodeType{NodeTypeCoordinator},
},
},
CreationTime: time.Now(),
}
confStored := Configuration{
Id: "test",
NetworkId: "testNetwork",
Nodes: []Node{
{
PeerId: "12D3KooWKLCajM89S8unbt3tgGbRLgmiWnFZT3adn9A5pQciBSLa",
Addresses: []string{"127.0.0.1:4830"},
Types: []NodeType{NodeTypeCoordinator},
},
},
CreationTime: time.Now(),
}
mergeCoordinatorAddrs(&confApp, &confStored)
t.Run("coorditor nodes are merged", func(t *testing.T) {
mergeCoordinatorAddrs(confApp, confStored)
assert.Equal(t, 2, len(confStored.Nodes[0].Addresses))
assert.Equal(t, "127.0.0.1:4830", confStored.Nodes[0].Addresses[0])
assert.Equal(t, "192.168.1.1:8833", confStored.Nodes[0].Addresses[1])
})
// (integration) old config yml and bad coordinator node;
// (unit) other config nodes are not affected;
// [x] (unit) peer id which doesn't exist is added;
}