...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package clientpool
17
18 import (
19 "strconv"
20 "testing"
21
22 . "github.com/onsi/gomega"
23 "k8s.io/apimachinery/pkg/runtime"
24 "k8s.io/client-go/rest"
25 pkgclient "sigs.k8s.io/controller-runtime/pkg/client"
26
27 "github.com/chaos-mesh/chaos-mesh/pkg/mock"
28 )
29
30 func TestClientPool(t *testing.T) {
31 g := NewWithT(t)
32
33 t.Run("client pool", func(t *testing.T) {
34 defer mock.With("MockCreateK8sClient", func(config *rest.Config, options pkgclient.Options) (pkgclient.Client, error) {
35 return nil, nil
36 })()
37
38 k8sClients, err := NewClientPool(&rest.Config{}, &runtime.Scheme{}, 5)
39 g.Expect(err).ToNot(HaveOccurred())
40
41 for i := 0; i < 6; i++ {
42 _, err := k8sClients.Client(strconv.Itoa(i))
43 g.Expect(err).ToNot(HaveOccurred())
44 }
45
46
47 g.Expect(k8sClients.Num()).To(Equal(5))
48
49 _, err = k8sClients.Client("6")
50 g.Expect(err).ToNot(HaveOccurred())
51
52
53 g.Expect(k8sClients.Contains("6")).To(Equal(true))
54 g.Expect(k8sClients.Contains("1")).To(Equal(false))
55 })
56 }
57