github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/lorry/engines/mock.go (about)

     1  /*
     2  Copyright (C) 2022-2023 ApeCloud Co., Ltd
     3  
     4  This file is part of KubeBlocks project
     5  
     6  This program is free software: you can redistribute it and/or modify
     7  it under the terms of the GNU Affero General Public License as published by
     8  the Free Software Foundation, either version 3 of the License, or
     9  (at your option) any later version.
    10  
    11  This program is distributed in the hope that it will be useful
    12  but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  GNU Affero General Public License for more details.
    15  
    16  You should have received a copy of the GNU Affero General Public License
    17  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18  */
    19  
    20  package engines
    21  
    22  import (
    23  	"context"
    24  	"fmt"
    25  
    26  	ctrl "sigs.k8s.io/controller-runtime"
    27  
    28  	"github.com/1aal/kubeblocks/pkg/lorry/dcs"
    29  )
    30  
    31  type MockManager struct {
    32  	DBManagerBase
    33  }
    34  
    35  var _ DBManager = &MockManager{}
    36  
    37  func NewMockManager(properties Properties) (DBManager, error) {
    38  	logger := ctrl.Log.WithName("MockManager")
    39  
    40  	managerBase, err := NewDBManagerBase(logger)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  
    45  	Mgr := &MockManager{
    46  		DBManagerBase: *managerBase,
    47  	}
    48  
    49  	return Mgr, nil
    50  }
    51  func (*MockManager) IsRunning() bool {
    52  	return true
    53  }
    54  
    55  func (*MockManager) IsDBStartupReady() bool {
    56  	return true
    57  }
    58  
    59  func (*MockManager) InitializeCluster(context.Context, *dcs.Cluster) error {
    60  	return fmt.Errorf("NotSupported")
    61  }
    62  func (*MockManager) IsClusterInitialized(context.Context, *dcs.Cluster) (bool, error) {
    63  	return false, fmt.Errorf("NotSupported")
    64  }
    65  
    66  func (*MockManager) IsCurrentMemberInCluster(context.Context, *dcs.Cluster) bool {
    67  	return true
    68  }
    69  
    70  func (*MockManager) IsCurrentMemberHealthy(context.Context, *dcs.Cluster) bool {
    71  	return true
    72  }
    73  
    74  func (*MockManager) IsClusterHealthy(context.Context, *dcs.Cluster) bool {
    75  	return true
    76  }
    77  
    78  func (*MockManager) IsMemberHealthy(context.Context, *dcs.Cluster, *dcs.Member) bool {
    79  	return true
    80  }
    81  
    82  func (*MockManager) HasOtherHealthyLeader(context.Context, *dcs.Cluster) *dcs.Member {
    83  	return nil
    84  }
    85  
    86  func (*MockManager) HasOtherHealthyMembers(context.Context, *dcs.Cluster, string) []*dcs.Member {
    87  	return nil
    88  }
    89  
    90  func (*MockManager) IsLeader(context.Context, *dcs.Cluster) (bool, error) {
    91  	return false, fmt.Errorf("NotSupported")
    92  }
    93  
    94  func (*MockManager) IsLeaderMember(context.Context, *dcs.Cluster, *dcs.Member) (bool, error) {
    95  	return false, fmt.Errorf("NotSupported")
    96  }
    97  
    98  func (*MockManager) IsFirstMember() bool {
    99  	return true
   100  }
   101  
   102  func (*MockManager) JoinCurrentMemberToCluster(context.Context, *dcs.Cluster) error {
   103  	return fmt.Errorf("NotSupported")
   104  }
   105  
   106  func (*MockManager) LeaveMemberFromCluster(context.Context, *dcs.Cluster, string) error {
   107  	return fmt.Errorf("NotSuppported")
   108  }
   109  
   110  func (*MockManager) Promote(context.Context, *dcs.Cluster) error {
   111  	return fmt.Errorf("NotSupported")
   112  }
   113  
   114  func (*MockManager) IsPromoted(context.Context) bool {
   115  	return true
   116  }
   117  
   118  func (*MockManager) Demote(context.Context) error {
   119  	return fmt.Errorf("NotSuppported")
   120  }
   121  
   122  func (*MockManager) Follow(context.Context, *dcs.Cluster) error {
   123  	return fmt.Errorf("NotSupported")
   124  }
   125  
   126  func (*MockManager) Recover(context.Context) error {
   127  	return nil
   128  
   129  }
   130  
   131  func (*MockManager) GetHealthiestMember(*dcs.Cluster, string) *dcs.Member {
   132  	return nil
   133  }
   134  
   135  func (*MockManager) GetMemberAddrs(context.Context, *dcs.Cluster) []string {
   136  	return nil
   137  }
   138  
   139  func (*MockManager) IsRootCreated(context.Context) (bool, error) {
   140  	return false, fmt.Errorf("NotSupported")
   141  }
   142  
   143  func (*MockManager) CreateRoot(context.Context) error {
   144  	return fmt.Errorf("NotSupported")
   145  }
   146  
   147  func (*MockManager) Lock(context.Context, string) error {
   148  	return fmt.Errorf("NotSuppported")
   149  }
   150  
   151  func (*MockManager) Unlock(context.Context) error {
   152  	return fmt.Errorf("NotSuppported")
   153  }