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 5package elastic 6 7import ( 8 "net/url" 9 "testing" 10) 11 12func TestSnapshotRepoValidate(t *testing.T) { 13 var client *Client 14 15 err := NewSnapshotDeleteService(client).Validate() 16 got := err.Error() 17 expected := "missing required fields: [Repository Snapshot]" 18 if got != expected { 19 t.Errorf("expected %q; got: %q", expected, got) 20 } 21} 22 23func TestSnapshotDeleteURL(t *testing.T) { 24 client := setupTestClient(t) 25 26 tests := []struct { 27 Repository string 28 Snapshot string 29 ExpectedPath string 30 ExpectedParams url.Values 31 }{ 32 { 33 Repository: "repo", 34 Snapshot: "snapshot_of_sunday", 35 ExpectedPath: "/_snapshot/repo/snapshot_of_sunday", 36 }, 37 { 38 Repository: "repö", 39 Snapshot: "001", 40 ExpectedPath: "/_snapshot/rep%C3%B6/001", 41 }, 42 } 43 44 for _, tt := range tests { 45 path, _, err := client.SnapshotDelete(tt.Repository, tt.Snapshot).buildURL() 46 if err != nil { 47 t.Fatal(err) 48 } 49 if path != tt.ExpectedPath { 50 t.Errorf("expected %q; got: %q", tt.ExpectedPath, path) 51 } 52 } 53} 54