Skip to content

Commit cecea71

Browse files
committed
Add tests for Cluster Reroute API
This commit adds some more tests to the Cluster Reroute API, while revisiting #1560. Close #1560
1 parent 3e40684 commit cecea71

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

cluster_reroute_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package elastic
77
import (
88
"context"
99
"net/url"
10+
"strings"
1011
"testing"
1112
)
1213

@@ -51,8 +52,18 @@ func TestClusterRerouteURLs(t *testing.T) {
5152
}
5253

5354
func TestClusterReroute(t *testing.T) {
55+
// client := setupTestClientAndCreateIndex(t, SetTraceLog(log.New(os.Stdout, "", 0)))
5456
client := setupTestClientAndCreateIndex(t)
5557

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) {
5667
// Get cluster nodes
5768
var nodes []string
5869
{
@@ -92,3 +103,23 @@ func TestClusterReroute(t *testing.T) {
92103
t.Fatalf("expected Status=%d, have %d", want, have)
93104
}
94105
}
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

Comments
 (0)