From 1db52861c1bf8effdcee9b2255b28bfafe6eeb92 Mon Sep 17 00:00:00 2001 From: husharp Date: Fri, 13 Sep 2024 17:42:44 +0800 Subject: [PATCH] make test happy Signed-off-by: husharp --- pkg/manager/member/pd_member_manager_test.go | 21 +++++--------------- pkg/pdapi/pd_control.go | 21 +++++++++++++++----- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/manager/member/pd_member_manager_test.go b/pkg/manager/member/pd_member_manager_test.go index 6799d38216..f6691e8c65 100644 --- a/pkg/manager/member/pd_member_manager_test.go +++ b/pkg/manager/member/pd_member_manager_test.go @@ -2873,6 +2873,7 @@ func TestPDMemberManagerSyncPDPeerUrlsSts(t *testing.T) { tcName := tc.Name pmm, _, _ := newFakePDMemberManager() + pmm.deps.PDControl = pdapi.NewFakePDControl(pmm.deps.KubeInformerFactory.Core().V1().Secrets().Lister(), true) fakePDControl := pmm.deps.PDControl.(*pdapi.FakePDControl) pdClient := controller.NewFakePDClient(fakePDControl, tc) etcdClient := controller.NewFakeEtcdClient(fakePDControl, tc) @@ -2929,21 +2930,15 @@ func TestPDMemberManagerSyncPDPeerUrlsSts(t *testing.T) { } }, pdHealth: &pdapi.HealthInfo{Healths: []pdapi.MemberHealth{ - {Name: "pd0", MemberID: uint64(1), ClientUrls: []string{"http://pd0:2379"}, Health: true}, - {Name: "pd1", MemberID: uint64(2), ClientUrls: []string{"http://pd1:2379"}, Health: true}, + {Name: "pd0", MemberID: 1, ClientUrls: []string{"http://pd0:2379"}, Health: true}, }}, membersInfo: &pdapi.MembersInfo{ Members: []*pdpb.Member{ { Name: "pd0", - MemberId: 111, + MemberId: 1, PeerUrls: []string{"http://pd0:2380"}, }, - { - Name: "pd1", - MemberId: 222, - PeerUrls: []string{"http://pd1:2380"}, - }, }, }, }, @@ -2967,21 +2962,15 @@ func TestPDMemberManagerSyncPDPeerUrlsSts(t *testing.T) { } }, pdHealth: &pdapi.HealthInfo{Healths: []pdapi.MemberHealth{ - {Name: "pd0", MemberID: uint64(1), ClientUrls: []string{"https://pd0:2379"}, Health: true}, - {Name: "pd1", MemberID: uint64(2), ClientUrls: []string{"https://pd1:2379"}, Health: true}, + {Name: "pd0", MemberID: 1, ClientUrls: []string{"https://pd0:2379"}, Health: true}, }}, membersInfo: &pdapi.MembersInfo{ Members: []*pdpb.Member{ { Name: "pd0", - MemberId: 111, + MemberId: 1, PeerUrls: []string{"https://pd0:2380"}, }, - { - Name: "pd1", - MemberId: 222, - PeerUrls: []string{"https://pd1:2380"}, - }, }, }, }, diff --git a/pkg/pdapi/pd_control.go b/pkg/pdapi/pd_control.go index c374f8bfea..a2960e0ed3 100644 --- a/pkg/pdapi/pd_control.go +++ b/pkg/pdapi/pd_control.go @@ -333,16 +333,27 @@ func genEtcdClientUrl(namespace Namespace, clusterName, clusterDomain string, he // FakePDControl implements a fake version of PDControlInterface. type FakePDControl struct { defaultPDControl + skipTLS bool } -func NewFakePDControl(secretLister corelisterv1.SecretLister) *FakePDControl { - return &FakePDControl{ - defaultPDControl{secretLister: secretLister, pdClients: map[string]PDClient{}, pdMSClients: map[string]PDMSClient{}, pdEtcdClients: map[string]PDEtcdClient{}}, +func NewFakePDControl(secretLister corelisterv1.SecretLister, skipTLS ...bool) *FakePDControl { + fake := &FakePDControl{ + defaultPDControl{secretLister: secretLister, pdClients: map[string]PDClient{}, + pdMSClients: map[string]PDMSClient{}, pdEtcdClients: map[string]PDEtcdClient{}}, + false, } + if len(skipTLS) > 0 { + fake.skipTLS = true + } + return fake } -func (fpc *FakePDControl) GetPDClient(namespace Namespace, tcName string, _ bool, _ ...Option) PDClient { - return fpc.defaultPDControl.pdClients[genClientKey("http", namespace, tcName, "")] +func (fpc *FakePDControl) GetPDClient(namespace Namespace, tcName string, tlsEnabled bool, opts ...Option) PDClient { + if fpc.skipTLS { + return fpc.defaultPDControl.pdClients[genClientKey("http", namespace, tcName, "")] + } + // return default GetPDClient + return fpc.defaultPDControl.GetPDClient(namespace, tcName, tlsEnabled, opts...) } func (fpc *FakePDControl) GetPDEtcdClient(namespace Namespace, tcName string, _ bool, _ ...Option) (PDEtcdClient, error) {