/
operator_autopilot_test.go
101 lines (86 loc) · 2.37 KB
/
operator_autopilot_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package apitests
import (
"testing"
"fmt"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require"
)
func TestAPI_OperatorAutopilotGetSetConfiguration(t *testing.T) {
t.Parallel()
require := require.New(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()
operator := c.Operator()
var config *api.AutopilotConfiguration
retry.Run(t, func(r *retry.R) {
var err error
config, _, err = operator.AutopilotGetConfiguration(nil)
r.Check(err)
})
require.True(config.CleanupDeadServers)
// Change a config setting
newConf := &api.AutopilotConfiguration{CleanupDeadServers: false}
_, err := operator.AutopilotSetConfiguration(newConf, nil)
require.Nil(err)
config, _, err = operator.AutopilotGetConfiguration(nil)
require.Nil(err)
require.False(config.CleanupDeadServers)
}
func TestAPI_OperatorAutopilotCASConfiguration(t *testing.T) {
t.Parallel()
require := require.New(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()
operator := c.Operator()
var config *api.AutopilotConfiguration
retry.Run(t, func(r *retry.R) {
var err error
config, _, err = operator.AutopilotGetConfiguration(nil)
r.Check(err)
})
require.True(config.CleanupDeadServers)
// Pass an invalid ModifyIndex
{
newConf := &api.AutopilotConfiguration{
CleanupDeadServers: false,
ModifyIndex: config.ModifyIndex - 1,
}
resp, _, err := operator.AutopilotCASConfiguration(newConf, nil)
require.Nil(err)
require.False(resp)
}
// Pass a valid ModifyIndex
{
newConf := &api.AutopilotConfiguration{
CleanupDeadServers: false,
ModifyIndex: config.ModifyIndex,
}
resp, _, err := operator.AutopilotCASConfiguration(newConf, nil)
require.Nil(err)
require.True(resp)
}
}
func TestAPI_OperatorAutopilotServerHealth(t *testing.T) {
t.Parallel()
c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) {
c.Server.RaftProtocol = 3
})
defer s.Stop()
operator := c.Operator()
testutil.WaitForResult(func() (bool, error) {
out, _, err := operator.AutopilotServerHealth(nil)
if err != nil {
return false, err
}
if len(out.Servers) != 1 ||
!out.Servers[0].Healthy ||
out.Servers[0].Name != fmt.Sprintf("%s.global", s.Config.NodeName) {
return false, fmt.Errorf("%v", out)
}
return true, nil
}, func(err error) {
t.Fatalf("err: %v", err)
})
}