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.

46 lines
1.0 KiB
Go

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