|
|
|
@ -5,41 +5,42 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Test_IsReadOnly(t *testing.T) {
|
|
|
|
|
var servers []*Server
|
|
|
|
|
var servers Servers
|
|
|
|
|
|
|
|
|
|
if _, found := IsReadOnly(nil, "1"); found {
|
|
|
|
|
if _, found := servers.IsReadOnly("1"); found {
|
|
|
|
|
t.Fatalf("found should be false")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
servers = make([]*Server, 1)
|
|
|
|
|
if _, found := IsReadOnly(servers, ""); found {
|
|
|
|
|
nodes := make([]*Server, 1)
|
|
|
|
|
servers = Servers(nodes)
|
|
|
|
|
if _, found := servers.IsReadOnly(""); found {
|
|
|
|
|
t.Fatalf("found should be false")
|
|
|
|
|
}
|
|
|
|
|
if _, found := IsReadOnly(servers, "node1"); found {
|
|
|
|
|
if _, found := servers.IsReadOnly("node1"); found {
|
|
|
|
|
t.Fatalf("found should be false")
|
|
|
|
|
}
|
|
|
|
|
servers[0] = &Server{
|
|
|
|
|
nodes[0] = &Server{
|
|
|
|
|
ID: "node1",
|
|
|
|
|
Addr: "localhost:4002",
|
|
|
|
|
Suffrage: "Voter",
|
|
|
|
|
}
|
|
|
|
|
if ro, found := IsReadOnly(servers, "node1"); ro || !found {
|
|
|
|
|
if ro, found := servers.IsReadOnly("node1"); ro || !found {
|
|
|
|
|
t.Fatalf("IsReadOnly returned ro: %t, found: %t", ro, found)
|
|
|
|
|
}
|
|
|
|
|
servers[0] = &Server{
|
|
|
|
|
nodes[0] = &Server{
|
|
|
|
|
ID: "node1",
|
|
|
|
|
Addr: "localhost:4002",
|
|
|
|
|
Suffrage: "Voter",
|
|
|
|
|
}
|
|
|
|
|
if ro, found := IsReadOnly(servers, "node2"); found {
|
|
|
|
|
if ro, found := servers.IsReadOnly("node2"); found {
|
|
|
|
|
t.Fatalf("IsReadOnly returned ro: %t, found: %t", ro, found)
|
|
|
|
|
}
|
|
|
|
|
servers[0] = &Server{
|
|
|
|
|
nodes[0] = &Server{
|
|
|
|
|
ID: "node1",
|
|
|
|
|
Addr: "localhost:4002",
|
|
|
|
|
Suffrage: "Nonvoter",
|
|
|
|
|
}
|
|
|
|
|
if ro, found := IsReadOnly(servers, "node1"); !ro || !found {
|
|
|
|
|
t.Fatalf("IsReadOnly returned ro: %t, found: %t", ro, found)
|
|
|
|
|
if ro, found := servers.IsReadOnly("node1"); !ro || !found {
|
|
|
|
|
t.Fatalf("servers.IsReadOnly returned ro: %t, found: %t", ro, found)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|