mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 06:16:08 +00:00
47c390025b
* First conversion * Use serf 0.8.2 tag and associated updated deps * * Move freeport and testutil into internal/ * Make internal/ its own module * Update imports * Add replace statements so API and normal Consul code are self-referencing for ease of development * Adapt to newer goe/values * Bump to new cleanhttp * Fix ban nonprintable chars test * Update lock bad args test The error message when the duration cannot be parsed changed in Go 1.12 (ae0c435877d3aacb9af5e706c40f9dddde5d3e67). This updates that test. * Update another test as well * Bump travis * Bump circleci * Bump go-discover and godo to get rid of launchpad dep * Bump dockerfile go version * fix tar command * Bump go-cleanhttp
108 lines
2.3 KiB
Go
108 lines
2.3 KiB
Go
package api
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/consul/internal/testutil"
|
|
"github.com/hashicorp/consul/internal/testutil/retry"
|
|
)
|
|
|
|
func TestAPI_OperatorAutopilotGetSetConfiguration(t *testing.T) {
|
|
t.Parallel()
|
|
c, s := makeClient(t)
|
|
defer s.Stop()
|
|
s.WaitForSerfCheck(t)
|
|
|
|
operator := c.Operator()
|
|
config, err := operator.AutopilotGetConfiguration(nil)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
if !config.CleanupDeadServers {
|
|
t.Fatalf("bad: %v", config)
|
|
}
|
|
|
|
// Change a config setting
|
|
newConf := &AutopilotConfiguration{CleanupDeadServers: false}
|
|
if err := operator.AutopilotSetConfiguration(newConf, nil); err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
|
|
config, err = operator.AutopilotGetConfiguration(nil)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
if config.CleanupDeadServers {
|
|
t.Fatalf("bad: %v", config)
|
|
}
|
|
}
|
|
|
|
func TestAPI_OperatorAutopilotCASConfiguration(t *testing.T) {
|
|
t.Parallel()
|
|
c, s := makeClient(t)
|
|
defer s.Stop()
|
|
|
|
retry.Run(t, func(r *retry.R) {
|
|
operator := c.Operator()
|
|
config, err := operator.AutopilotGetConfiguration(nil)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
if !config.CleanupDeadServers {
|
|
t.Fatalf("bad: %v", config)
|
|
}
|
|
|
|
// Pass an invalid ModifyIndex
|
|
{
|
|
newConf := &AutopilotConfiguration{
|
|
CleanupDeadServers: false,
|
|
ModifyIndex: config.ModifyIndex - 1,
|
|
}
|
|
resp, err := operator.AutopilotCASConfiguration(newConf, nil)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
if resp {
|
|
t.Fatalf("bad: %v", resp)
|
|
}
|
|
}
|
|
|
|
// Pass a valid ModifyIndex
|
|
{
|
|
newConf := &AutopilotConfiguration{
|
|
CleanupDeadServers: false,
|
|
ModifyIndex: config.ModifyIndex,
|
|
}
|
|
resp, err := operator.AutopilotCASConfiguration(newConf, nil)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
if !resp {
|
|
t.Fatalf("bad: %v", resp)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestAPI_OperatorAutopilotServerHealth(t *testing.T) {
|
|
t.Parallel()
|
|
c, s := makeClientWithConfig(t, nil, func(c *testutil.TestServerConfig) {
|
|
c.RaftProtocol = 3
|
|
})
|
|
defer s.Stop()
|
|
|
|
operator := c.Operator()
|
|
retry.Run(t, func(r *retry.R) {
|
|
out, err := operator.AutopilotServerHealth(nil)
|
|
if err != nil {
|
|
r.Fatalf("err: %v", err)
|
|
}
|
|
|
|
if len(out.Servers) != 1 ||
|
|
!out.Servers[0].Healthy ||
|
|
out.Servers[0].Name != s.Config.NodeName {
|
|
r.Fatalf("bad: %v", out)
|
|
}
|
|
})
|
|
}
|