Skip to content

Commit

Permalink
Add tests for Cluster Reroute API
Browse files Browse the repository at this point in the history
This commit adds some more tests to the Cluster Reroute API, while
revisiting #1560.

Close #1560
  • Loading branch information
olivere committed Jan 7, 2022
1 parent 3e40684 commit cecea71
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cluster_reroute_test.go
Expand Up @@ -7,6 +7,7 @@ package elastic
import (
"context"
"net/url"
"strings"
"testing"
)

Expand Down Expand Up @@ -51,8 +52,18 @@ func TestClusterRerouteURLs(t *testing.T) {
}

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

t.Run("Commands", func(t *testing.T) {
testClusterRerouteWithCommands(client, t)
})
t.Run("NoBody", func(t *testing.T) {
testClusterRerouteWithoutBody(client, t)
})
}

func testClusterRerouteWithCommands(client *Client, t *testing.T) {
// Get cluster nodes
var nodes []string
{
Expand Down Expand Up @@ -92,3 +103,23 @@ func TestClusterReroute(t *testing.T) {
t.Fatalf("expected Status=%d, have %d", want, have)
}
}

func testClusterRerouteWithoutBody(client *Client, t *testing.T) {
// Perform a nop cluster reroute
res, err := client.ClusterReroute().
DryRun(true).
Pretty(true).
RetryFailed(true).
MasterTimeout("10s").
Do(context.Background())
// Expect an error here: We just test if it's of a specific kind
if err == nil {
t.Fatal("expected an error, got nil")
}
if res != nil {
t.Fatalf("expected res to be != nil; got: %v", res)
}
if !strings.Contains(err.Error(), "missing allocate commands or raw body") {
t.Fatalf("expected Error~=%s, have %s", "missing allocate commands or raw body", err.Error())
}
}

0 comments on commit cecea71

Please sign in to comment.