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