| 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 |
"testing" |
| 9 |
) |
| 10 |
|
| 11 |
func TestIndexGetTemplateURL(t *testing.T) { |
| 12 |
client := setupTestClientAndCreateIndex(t) |
| 13 |
|
| 14 |
tests := []struct { |
| 15 |
Names []string |
| 16 |
Expected string |
| 17 |
}{ |
| 18 |
{ |
| 19 |
[]string{}, |
| 20 |
"/_template", |
| 21 |
}, |
| 22 |
{ |
| 23 |
[]string{"index1"}, |
| 24 |
"/_template/index1", |
| 25 |
}, |
| 26 |
{ |
| 27 |
[]string{"index1", "index2"}, |
| 28 |
"/_template/index1%2Cindex2", |
| 29 |
}, |
| 30 |
} |
| 31 |
|
| 32 |
for _, test := range tests { |
| 33 |
path, _, err := client.IndexGetTemplate().Name(test.Names...).buildURL() |
| 34 |
if err != nil { |
| 35 |
t.Fatal(err) |
| 36 |
} |
| 37 |
if path != test.Expected { |
| 38 |
t.Errorf("expected %q; got: %q", test.Expected, path) |
| 39 |
} |
| 40 |
} |
| 41 |
} |