forked from olivere/elastic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cat_aliases_test.go
55 lines (49 loc) · 1.34 KB
/
cat_aliases_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2012-present Oliver Eilhard. All rights reserved.
// Use of this source code is governed by a MIT-license.
// See http://olivere.mit-license.org/license.txt for details.
package elastic
import (
"context"
"testing"
)
func TestCatAliases(t *testing.T) {
client := setupTestClientAndCreateIndexAndAddDocs(t, SetDecoder(&strictDecoder{})) //, SetTraceLog(log.New(os.Stdout, "", 0)))
ctx := context.Background()
// Add two aliases
_, err := client.Alias().
Add(testIndexName, testAliasName).
Action(NewAliasAddAction(testAliasName2).Index(testIndexName2)).
Do(context.TODO())
if err != nil {
t.Fatal(err)
}
defer func() {
// Remove aliases
client.Alias().
Remove(testIndexName, testAliasName).
Remove(testIndexName2, testAliasName2).
Do(context.TODO())
}()
// Check all aliases
res, err := client.CatAliases().Pretty(true).Columns("*").Do(ctx)
if err != nil {
t.Fatal(err)
}
if res == nil {
t.Fatal("want response, have nil")
}
if want, have := 2, len(res); want != have {
t.Fatalf("want len=%d, have %d", want, have)
}
// Check a named alias
res, err = client.CatAliases().Alias(testAliasName).Pretty(true).Do(ctx)
if err != nil {
t.Fatal(err)
}
if res == nil {
t.Fatal("want response, have nil")
}
if want, have := 1, len(res); want != have {
t.Fatalf("want len=%d, have %d", want, have)
}
}