1// Copyright 2012-2018 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 TestXPackSecurityGetRoleBuildURL(t *testing.T) {
12	client := setupTestClientForXpackSecurity(t)
13
14	tests := []struct {
15		Name         string
16		ExpectedPath string
17		ExpectErr    bool
18	}{
19		{
20			"",
21			"",
22			true,
23		},
24		{
25			"my-role",
26			"/_xpack/security/role/my-role",
27			false,
28		},
29	}
30
31	for i, test := range tests {
32		builder := client.XPackSecurityGetRole(test.Name)
33		err := builder.Validate()
34		if err != nil {
35			if !test.ExpectErr {
36				t.Errorf("case #%d: %v", i+1, err)
37				continue
38			}
39		} else {
40			// err == nil
41			if test.ExpectErr {
42				t.Errorf("case #%d: expected error", i+1)
43				continue
44			}
45			path, _, _ := builder.buildURL()
46			if path != test.ExpectedPath {
47				t.Errorf("case #%d: expected %q; got: %q", i+1, test.ExpectedPath, path)
48			}
49		}
50	}
51}
52