-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalias_test.go
111 lines (104 loc) · 2.04 KB
/
alias_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package eskeeper
import (
"context"
"testing"
"time"
)
func TestExistAlias(t *testing.T) {
tests := []struct {
name string
alias string
setup func(tb testing.TB)
want bool
cleanup func(tb testing.TB)
}{
{
name: "simple",
alias: "alias-exist-v1",
setup: func(tb testing.TB) {
createTmpIndexHelper(tb, "alias-exist-index-v1")
createTmpIndexHelper(tb, "alias-exist-index-v2")
time.Sleep(10 * time.Second)
createTmpAliasHelper(tb, "alias-exist-v1", "alias-exist-index-v1")
createTmpAliasHelper(tb, "alias-exist-v1", "alias-exist-index-v2")
},
want: true,
},
{
name: "not-found",
alias: "not-found",
setup: func(tb testing.TB) {
},
want: false,
},
}
es, err := newEsClient([]string{url}, "", "")
if err != nil {
t.Fatal(err)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()
tt.setup(t)
ok, err := es.existAlias(ctx, tt.alias)
if err != nil {
t.Error(err)
}
if ok != tt.want {
t.Errorf("want: %+v, got: %+v\n", tt.want, ok)
}
})
}
}
func TestSyncAliases(t *testing.T) {
tests := []struct {
name string
conf config
setup func(tb testing.TB)
cleanup func(tb testing.TB)
}{
{
name: "simple",
conf: config{
Aliases: []alias{
{
Name: "test-sync-alias",
Indices: []string{"test-v1", "test-v2"},
},
},
},
setup: func(tb testing.TB) {
createTmpIndexHelper(tb, "test-v1")
createTmpIndexHelper(tb, "test-v2")
},
},
{
name: "switch",
conf: config{
Aliases: []alias{
{
Name: "test-sync-alias",
Indices: []string{"test-v3"},
},
},
},
setup: func(tb testing.TB) {
createTmpIndexHelper(tb, "test-v3")
},
},
}
es, err := newEsClient([]string{url}, "", "")
if err != nil {
t.Fatal(err)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()
tt.setup(t)
err := es.syncAliases(ctx, tt.conf)
if err != nil {
t.Error(err)
}
})
}
}