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	"testing"
9)
10
11func TestIndicesGetFieldMappingURL(t *testing.T) {
12	client := setupTestClientAndCreateIndex(t)
13
14	tests := []struct {
15		Indices  []string
16		Types    []string
17		Fields   []string
18		Expected string
19	}{
20		{
21			[]string{},
22			[]string{},
23			[]string{},
24			"/_all/_mapping/_all/field/%2A",
25		},
26		{
27			[]string{},
28			[]string{"tweet"},
29			[]string{"message"},
30			"/_all/_mapping/tweet/field/message",
31		},
32		{
33			[]string{"twitter"},
34			[]string{"tweet"},
35			[]string{"*.id"},
36			"/twitter/_mapping/tweet/field/%2A.id",
37		},
38		{
39			[]string{"store-1", "store-2"},
40			[]string{"tweet", "user"},
41			[]string{"message", "*.id"},
42			"/store-1%2Cstore-2/_mapping/tweet%2Cuser/field/message%2C%2A.id",
43		},
44	}
45
46	for _, test := range tests {
47		path, _, err := client.GetFieldMapping().Index(test.Indices...).Type(test.Types...).Field(test.Fields...).buildURL()
48		if err != nil {
49			t.Fatal(err)
50		}
51		if path != test.Expected {
52			t.Errorf("expected %q; got: %q", test.Expected, path)
53		}
54	}
55}
56