1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB
Go

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