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 TestXPackWatcherExecuteWatchBuildURL(t *testing.T) {
12	client := setupTestClient(t) // , SetURL("http://elastic:elastic@localhost:9210"))
13
14	tests := []struct {
15		Id        string
16		Expected  string
17		ExpectErr bool
18	}{
19		{
20			"",
21			"/_xpack/watcher/watch/_execute",
22			false,
23		},
24		{
25			"my-watch",
26			"/_xpack/watcher/watch/my-watch/_execute",
27			false,
28		},
29	}
30
31	for i, test := range tests {
32		builder := client.XPackWatchExecute().Id(test.Id)
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.Expected {
47				t.Errorf("case #%d: expected %q; got: %q", i+1, test.Expected, path)
48			}
49		}
50	}
51}
52