From cecea717bb9cf4f476f1e11207f15398f0e51165 Mon Sep 17 00:00:00 2001 From: Oliver Eilhard Date: Fri, 7 Jan 2022 17:35:34 +0100 Subject: [PATCH] Add tests for Cluster Reroute API This commit adds some more tests to the Cluster Reroute API, while revisiting #1560. Close #1560 --- cluster_reroute_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cluster_reroute_test.go b/cluster_reroute_test.go index d8966d1a9..5bb09bdcb 100644 --- a/cluster_reroute_test.go +++ b/cluster_reroute_test.go @@ -7,6 +7,7 @@ package elastic import ( "context" "net/url" + "strings" "testing" ) @@ -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 { @@ -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()) + } +}