| 1 |
// Copyright 2012-present Oliver Eilhard. All rights reserved. |
| 2 |
// Use of this source code is governed by a MIT-license. |
| 3 |
// See http://olivere.mit-license.org/license.txt for details. |
| 4 |
|
| 5 |
package elastic |
| 6 |
|
| 7 |
import ( |
| 8 |
"context" |
| 9 |
"testing" |
| 10 |
) |
| 11 |
|
| 12 |
func TestTasksListBuildURL(t *testing.T) { |
| 13 |
client := setupTestClient(t) |
| 14 |
|
| 15 |
tests := []struct { |
| 16 |
TaskId []string |
| 17 |
Expected string |
| 18 |
}{ |
| 19 |
{ |
| 20 |
[]string{}, |
| 21 |
"/_tasks", |
| 22 |
}, |
| 23 |
{ |
| 24 |
[]string{"42"}, |
| 25 |
"/_tasks/42", |
| 26 |
}, |
| 27 |
{ |
| 28 |
[]string{"42", "37"}, |
| 29 |
"/_tasks/42%2C37", |
| 30 |
}, |
| 31 |
} |
| 32 |
|
| 33 |
for i, test := range tests { |
| 34 |
path, _, err := client.TasksList().TaskId(test.TaskId...).buildURL() |
| 35 |
if err != nil { |
| 36 |
t.Errorf("case #%d: %v", i+1, err) |
| 37 |
continue |
| 38 |
} |
| 39 |
if path != test.Expected { |
| 40 |
t.Errorf("case #%d: expected %q; got: %q", i+1, test.Expected, path) |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
func TestTasksList(t *testing.T) { |
| 46 |
client := setupTestClientAndCreateIndexAndAddDocs(t) //, SetTraceLog(log.New(os.Stdout, "", 0))) |
| 47 |
esversion, err := client.ElasticsearchVersion(DefaultURL) |
| 48 |
if err != nil { |
| 49 |
t.Fatal(err) |
| 50 |
} |
| 51 |
if esversion < "2.3.0" { |
| 52 |
t.Skipf("Elasticsearch %v does not support Tasks Management API yet", esversion) |
| 53 |
} |
| 54 |
|
| 55 |
res, err := client.TasksList().Pretty(true).Do(context.TODO()) |
| 56 |
if err != nil { |
| 57 |
t.Fatal(err) |
| 58 |
} |
| 59 |
if res == nil { |
| 60 |
t.Fatal("response is nil") |
| 61 |
} |
| 62 |
if len(res.Nodes) == 0 { |
| 63 |
t.Fatalf("expected at least 1 node; got: %d", len(res.Nodes)) |
| 64 |
} |
| 65 |
} |