@@ -7,6 +7,7 @@ package elastic
7
7
import (
8
8
"context"
9
9
"net/url"
10
+ "strings"
10
11
"testing"
11
12
)
12
13
@@ -51,8 +52,18 @@ func TestClusterRerouteURLs(t *testing.T) {
51
52
}
52
53
53
54
func TestClusterReroute (t * testing.T ) {
55
+ // client := setupTestClientAndCreateIndex(t, SetTraceLog(log.New(os.Stdout, "", 0)))
54
56
client := setupTestClientAndCreateIndex (t )
55
57
58
+ t .Run ("Commands" , func (t * testing.T ) {
59
+ testClusterRerouteWithCommands (client , t )
60
+ })
61
+ t .Run ("NoBody" , func (t * testing.T ) {
62
+ testClusterRerouteWithoutBody (client , t )
63
+ })
64
+ }
65
+
66
+ func testClusterRerouteWithCommands (client * Client , t * testing.T ) {
56
67
// Get cluster nodes
57
68
var nodes []string
58
69
{
@@ -92,3 +103,23 @@ func TestClusterReroute(t *testing.T) {
92
103
t .Fatalf ("expected Status=%d, have %d" , want , have )
93
104
}
94
105
}
106
+
107
+ func testClusterRerouteWithoutBody (client * Client , t * testing.T ) {
108
+ // Perform a nop cluster reroute
109
+ res , err := client .ClusterReroute ().
110
+ DryRun (true ).
111
+ Pretty (true ).
112
+ RetryFailed (true ).
113
+ MasterTimeout ("10s" ).
114
+ Do (context .Background ())
115
+ // Expect an error here: We just test if it's of a specific kind
116
+ if err == nil {
117
+ t .Fatal ("expected an error, got nil" )
118
+ }
119
+ if res != nil {
120
+ t .Fatalf ("expected res to be != nil; got: %v" , res )
121
+ }
122
+ if ! strings .Contains (err .Error (), "missing allocate commands or raw body" ) {
123
+ t .Fatalf ("expected Error~=%s, have %s" , "missing allocate commands or raw body" , err .Error ())
124
+ }
125
+ }
0 commit comments