snapshot_create_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package elastic
  2. import (
  3. "net/url"
  4. "reflect"
  5. "testing"
  6. )
  7. func TestSnapshotValidate(t *testing.T) {
  8. var client *Client
  9. err := NewSnapshotCreateService(client).Validate()
  10. got := err.Error()
  11. expected := "missing required fields: [Repository Snapshot]"
  12. if got != expected {
  13. t.Errorf("expected %q; got: %q", expected, got)
  14. }
  15. }
  16. func TestSnapshotPutURL(t *testing.T) {
  17. client := setupTestClient(t)
  18. tests := []struct {
  19. Repository string
  20. Snapshot string
  21. Pretty bool
  22. MasterTimeout string
  23. WaitForCompletion bool
  24. ExpectedPath string
  25. ExpectedParams url.Values
  26. }{
  27. {
  28. Repository: "repo",
  29. Snapshot: "snapshot_of_sunday",
  30. Pretty: true,
  31. MasterTimeout: "60s",
  32. WaitForCompletion: true,
  33. ExpectedPath: "/_snapshot/repo/snapshot_of_sunday",
  34. ExpectedParams: url.Values{
  35. "pretty": []string{"1"},
  36. "master_timeout": []string{"60s"},
  37. "wait_for_completion": []string{"true"},
  38. },
  39. },
  40. }
  41. for _, test := range tests {
  42. path, params, err := client.SnapshotCreate(test.Repository, test.Snapshot).
  43. Pretty(test.Pretty).
  44. MasterTimeout(test.MasterTimeout).
  45. WaitForCompletion(test.WaitForCompletion).
  46. buildURL()
  47. if err != nil {
  48. t.Fatal(err)
  49. }
  50. if path != test.ExpectedPath {
  51. t.Errorf("expected %q; got: %q", test.ExpectedPath, path)
  52. }
  53. if !reflect.DeepEqual(params, test.ExpectedParams) {
  54. t.Errorf("expected %q; got: %q", test.ExpectedParams, params)
  55. }
  56. }
  57. }