tasks_list_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. package elastic
  5. import (
  6. "context"
  7. "testing"
  8. )
  9. func TestTasksListBuildURL(t *testing.T) {
  10. client := setupTestClient(t)
  11. tests := []struct {
  12. TaskId []string
  13. Expected string
  14. }{
  15. {
  16. []string{},
  17. "/_tasks",
  18. },
  19. {
  20. []string{"42"},
  21. "/_tasks/42",
  22. },
  23. {
  24. []string{"42", "37"},
  25. "/_tasks/42%2C37",
  26. },
  27. }
  28. for i, test := range tests {
  29. path, _, err := client.TasksList().TaskId(test.TaskId...).buildURL()
  30. if err != nil {
  31. t.Errorf("case #%d: %v", i+1, err)
  32. continue
  33. }
  34. if path != test.Expected {
  35. t.Errorf("case #%d: expected %q; got: %q", i+1, test.Expected, path)
  36. }
  37. }
  38. }
  39. func TestTasksList(t *testing.T) {
  40. client := setupTestClientAndCreateIndexAndAddDocs(t) //, SetTraceLog(log.New(os.Stdout, "", 0)))
  41. esversion, err := client.ElasticsearchVersion(DefaultURL)
  42. if err != nil {
  43. t.Fatal(err)
  44. }
  45. if esversion < "2.3.0" {
  46. t.Skipf("Elasticsearch %v does not support Tasks Management API yet", esversion)
  47. }
  48. res, err := client.TasksList().Pretty(true).Do(context.TODO())
  49. if err != nil {
  50. t.Fatal(err)
  51. }
  52. if res == nil {
  53. t.Fatal("response is nil")
  54. }
  55. if len(res.Nodes) == 0 {
  56. t.Fatalf("expected at least 1 node; got: %d", len(res.Nodes))
  57. }
  58. }