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