-
Notifications
You must be signed in to change notification settings - Fork 534
Expand file tree
/
Copy pathselector_test.go
More file actions
110 lines (93 loc) · 3.45 KB
/
selector_test.go
File metadata and controls
110 lines (93 loc) · 3.45 KB
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
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package volumes
import (
"testing"
. "github.com/onsi/gomega"
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
)
func TestNewSelector(t *testing.T) {
cases := []struct {
desc string
instance string
mt v1alpha1.MemberType
expected string
expectedHasErr bool
}{
{
desc: "selector for pd",
instance: "aaa",
mt: v1alpha1.PDMemberType,
expected: "app.kubernetes.io/component=pd,app.kubernetes.io/instance=aaa,app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster",
},
{
desc: "selector for tso",
instance: "aaa",
mt: v1alpha1.PDMSTSOMemberType,
expected: "app.kubernetes.io/component=tso,app.kubernetes.io/instance=aaa,app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster",
},
{
desc: "selector for scheduling",
instance: "aaa",
mt: v1alpha1.PDMSSchedulingMemberType,
expected: "app.kubernetes.io/component=scheduling,app.kubernetes.io/instance=aaa,app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster",
},
{
desc: "selector for router",
instance: "aaa",
mt: v1alpha1.PDMSRouterMerberType,
expected: "app.kubernetes.io/component=router,app.kubernetes.io/instance=aaa,app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster",
},
{
desc: "selector for tidb",
instance: "aaa",
mt: v1alpha1.TiDBMemberType,
expected: "app.kubernetes.io/component=tidb,app.kubernetes.io/instance=aaa,app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster",
},
{
desc: "selector for tikv",
instance: "aaa",
mt: v1alpha1.TiKVMemberType,
expected: "app.kubernetes.io/component=tikv,app.kubernetes.io/instance=aaa,app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster",
},
{
desc: "selector for tiflash",
instance: "aaa",
mt: v1alpha1.TiFlashMemberType,
expected: "app.kubernetes.io/component=tiflash,app.kubernetes.io/instance=aaa,app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster",
},
{
desc: "selector for ticdc",
instance: "aaa",
mt: v1alpha1.TiCDCMemberType,
expected: "app.kubernetes.io/component=ticdc,app.kubernetes.io/instance=aaa,app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster",
},
{
desc: "selector for pump",
instance: "aaa",
mt: v1alpha1.PumpMemberType,
expected: "app.kubernetes.io/component=pump,app.kubernetes.io/instance=aaa,app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster",
},
}
sf := MustNewSelectorFactory()
g := NewGomegaWithT(t)
for _, c := range cases {
s, err := sf.NewSelector(c.instance, c.mt)
if c.expectedHasErr {
g.Expect(err).Should(HaveOccurred())
} else {
g.Expect(err).Should(Succeed(), c.desc)
}
g.Expect(s.String()).Should(Equal(c.expected), c.desc)
}
}