Skip to content

Commit

Permalink
make test happy
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <ihusharp@gmail.com>
  • Loading branch information
HuSharp committed Sep 13, 2024
1 parent 16e4355 commit 1db5286
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 5 additions & 16 deletions pkg/manager/member/pd_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"},
},
},
},
},
Expand All @@ -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"},
},
},
},
},
Expand Down
21 changes: 16 additions & 5 deletions pkg/pdapi/pd_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1db5286

Please sign in to comment.