|
|
|
@ -60,6 +60,7 @@ func TestIsConsulServer(t *testing.T) {
|
|
|
|
|
"dc": "east-aws",
|
|
|
|
|
"port": "10000",
|
|
|
|
|
"vsn": "1",
|
|
|
|
|
"expect": "3",
|
|
|
|
|
"raft_vsn": "3",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
@ -76,7 +77,7 @@ func TestIsConsulServer(t *testing.T) {
|
|
|
|
|
if parts.Bootstrap {
|
|
|
|
|
t.Fatalf("unexpected bootstrap")
|
|
|
|
|
}
|
|
|
|
|
if parts.Expect != 0 {
|
|
|
|
|
if parts.Expect != 3 {
|
|
|
|
|
t.Fatalf("bad: %v", parts.Expect)
|
|
|
|
|
}
|
|
|
|
|
if parts.RaftVersion != 3 {
|
|
|
|
@ -114,3 +115,69 @@ func TestIsConsulServer(t *testing.T) {
|
|
|
|
|
t.Fatalf("unexpected ok server")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestIsConsulServer_Optional(t *testing.T) {
|
|
|
|
|
m := serf.Member{
|
|
|
|
|
Name: "foo",
|
|
|
|
|
Addr: net.IP([]byte{127, 0, 0, 1}),
|
|
|
|
|
Tags: map[string]string{
|
|
|
|
|
"role": "consul",
|
|
|
|
|
"id": "asdf",
|
|
|
|
|
"dc": "east-aws",
|
|
|
|
|
"port": "10000",
|
|
|
|
|
"vsn": "1",
|
|
|
|
|
// raft_vsn and expect are optional and should default
|
|
|
|
|
// to zero.
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
ok, parts := agent.IsConsulServer(m)
|
|
|
|
|
if !ok || parts.Datacenter != "east-aws" || parts.Port != 10000 {
|
|
|
|
|
t.Fatalf("bad: %v %v", ok, parts)
|
|
|
|
|
}
|
|
|
|
|
if parts.Name != "foo" {
|
|
|
|
|
t.Fatalf("bad: %v", parts)
|
|
|
|
|
}
|
|
|
|
|
if parts.ID != "asdf" {
|
|
|
|
|
t.Fatalf("bad: %v", parts.ID)
|
|
|
|
|
}
|
|
|
|
|
if parts.Bootstrap {
|
|
|
|
|
t.Fatalf("unexpected bootstrap")
|
|
|
|
|
}
|
|
|
|
|
if parts.Expect != 0 {
|
|
|
|
|
t.Fatalf("bad: %v", parts.Expect)
|
|
|
|
|
}
|
|
|
|
|
if parts.RaftVersion != 0 {
|
|
|
|
|
t.Fatalf("bad: %v", parts.RaftVersion)
|
|
|
|
|
}
|
|
|
|
|
m.Tags["bootstrap"] = "1"
|
|
|
|
|
m.Tags["disabled"] = "1"
|
|
|
|
|
ok, parts = agent.IsConsulServer(m)
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatalf("expected a valid consul server")
|
|
|
|
|
}
|
|
|
|
|
if !parts.Bootstrap {
|
|
|
|
|
t.Fatalf("expected bootstrap")
|
|
|
|
|
}
|
|
|
|
|
if parts.Addr.String() != "127.0.0.1:10000" {
|
|
|
|
|
t.Fatalf("bad addr: %v", parts.Addr)
|
|
|
|
|
}
|
|
|
|
|
if parts.Version != 1 {
|
|
|
|
|
t.Fatalf("bad: %v", parts)
|
|
|
|
|
}
|
|
|
|
|
m.Tags["expect"] = "3"
|
|
|
|
|
delete(m.Tags, "bootstrap")
|
|
|
|
|
delete(m.Tags, "disabled")
|
|
|
|
|
ok, parts = agent.IsConsulServer(m)
|
|
|
|
|
if !ok || parts.Expect != 3 {
|
|
|
|
|
t.Fatalf("bad: %v", parts.Expect)
|
|
|
|
|
}
|
|
|
|
|
if parts.Bootstrap {
|
|
|
|
|
t.Fatalf("unexpected bootstrap")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete(m.Tags, "role")
|
|
|
|
|
ok, parts = agent.IsConsulServer(m)
|
|
|
|
|
if ok {
|
|
|
|
|
t.Fatalf("unexpected ok server")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|