github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libkbfs/config_mock_test.go (about)

     1  // Copyright 2016 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package libkbfs
     6  
     7  import (
     8  	"github.com/golang/mock/gomock"
     9  	"github.com/keybase/client/go/kbfs/data"
    10  	"github.com/keybase/client/go/kbfs/kbfscodec"
    11  	"github.com/keybase/client/go/kbfs/kbfsedits"
    12  	"github.com/keybase/client/go/kbfs/tlfhandle"
    13  	"github.com/keybase/client/go/logger"
    14  	"github.com/keybase/client/go/protocol/keybase1"
    15  	"golang.org/x/net/context"
    16  )
    17  
    18  type FakeObserver struct {
    19  	localChange  Node
    20  	batchChanges []NodeChange
    21  	ctx          context.Context
    22  }
    23  
    24  func (fn *FakeObserver) LocalChange(ctx context.Context,
    25  	node Node, write WriteRange) {
    26  	fn.localChange = node
    27  	fn.ctx = ctx
    28  }
    29  
    30  func (fn *FakeObserver) BatchChanges(
    31  	ctx context.Context, nodeChanges []NodeChange, _ []NodeID) {
    32  	fn.batchChanges = nodeChanges
    33  	fn.ctx = ctx
    34  }
    35  
    36  func (fn *FakeObserver) TlfHandleChange(ctx context.Context,
    37  	newHandle *tlfhandle.Handle) {
    38  }
    39  
    40  type ConfigMock struct {
    41  	ConfigLocal
    42  
    43  	// local references to the proper mock type
    44  	mockKbfs                         *MockKBFSOps
    45  	mockKbpki                        *MockKBPKI
    46  	mockKbs                          *MockKeybaseService
    47  	mockKeyman                       *MockKeyManager
    48  	mockRep                          *MockReporter
    49  	mockMdcache                      *MockMDCache
    50  	mockKcache                       *MockKeyCache
    51  	mockBcache                       *MockBlockCache
    52  	mockDirtyBcache                  *MockDirtyBlockCache
    53  	mockCrypto                       *MockCrypto
    54  	mockChat                         *MockChat
    55  	mockCodec                        *kbfscodec.MockCodec
    56  	mockMdops                        *MockMDOps
    57  	mockKops                         *MockKeyOps
    58  	mockBops                         *MockBlockOps
    59  	mockMdserv                       *MockMDServer
    60  	mockKserv                        *MockKeyServer
    61  	mockBserv                        *MockBlockServer
    62  	mockBsplit                       *MockBlockSplitter
    63  	mockNotifier                     *MockNotifier
    64  	mockClock                        *MockClock
    65  	mockRekeyQueue                   *MockRekeyQueue
    66  	mockSubscriptionManagerPublisher *MockSubscriptionManagerPublisher
    67  	observer                         *FakeObserver
    68  	ctr                              *SafeTestReporter
    69  }
    70  
    71  func NewConfigMock(c *gomock.Controller, ctr *SafeTestReporter) *ConfigMock {
    72  	config := &ConfigMock{
    73  		ConfigLocal: ConfigLocal{
    74  			loggerFn: func(m string) logger.Logger {
    75  				return logger.NewTestLogger(ctr.t)
    76  			},
    77  			quotaUsage: make(
    78  				map[keybase1.UserOrTeamID]*EventuallyConsistentQuotaUsage),
    79  		},
    80  	}
    81  	config.mockKbfs = NewMockKBFSOps(c)
    82  	config.SetKBFSOps(config.mockKbfs)
    83  	config.mockKbs = NewMockKeybaseService(c)
    84  	config.SetKeybaseService(config.mockKbs)
    85  	config.mockKbpki = NewMockKBPKI(c)
    86  	config.SetKBPKI(config.mockKbpki)
    87  	config.mockKeyman = NewMockKeyManager(c)
    88  	config.SetKeyManager(config.mockKeyman)
    89  	config.mockRep = NewMockReporter(c)
    90  	config.SetReporter(config.mockRep)
    91  	config.mockMdcache = NewMockMDCache(c)
    92  	config.SetMDCache(config.mockMdcache)
    93  	config.mockKcache = NewMockKeyCache(c)
    94  	config.SetKeyCache(config.mockKcache)
    95  	config.mockBcache = NewMockBlockCache(c)
    96  	config.SetBlockCache(config.mockBcache)
    97  	config.mockDirtyBcache = NewMockDirtyBlockCache(c)
    98  	config.SetDirtyBlockCache(config.mockDirtyBcache)
    99  	config.mockCrypto = NewMockCrypto(c)
   100  	config.SetCrypto(config.mockCrypto)
   101  	config.mockChat = NewMockChat(c)
   102  	config.SetChat(config.mockChat)
   103  	config.mockCodec = kbfscodec.NewMockCodec(c)
   104  	config.mockCodec.EXPECT().RegisterType(gomock.Any(), gomock.Any()).
   105  		AnyTimes().Return()
   106  	config.mockCodec.EXPECT().RegisterIfaceSliceType(gomock.Any(),
   107  		gomock.Any(), gomock.Any()).AnyTimes().Return()
   108  	config.SetCodec(config.mockCodec)
   109  	config.mockMdops = NewMockMDOps(c)
   110  	config.SetMDOps(config.mockMdops)
   111  	config.mockKops = NewMockKeyOps(c)
   112  	config.SetKeyOps(config.mockKops)
   113  	config.mockBops = NewMockBlockOps(c)
   114  	config.SetBlockOps(config.mockBops)
   115  	config.mockMdserv = NewMockMDServer(c)
   116  	// Ignore all reconnect backoff fast forwards
   117  	config.mockMdserv.EXPECT().FastForwardBackoff().AnyTimes()
   118  	config.SetMDServer(config.mockMdserv)
   119  	config.mockKserv = NewMockKeyServer(c)
   120  	config.SetKeyServer(config.mockKserv)
   121  	config.mockBserv = NewMockBlockServer(c)
   122  	config.SetBlockServer(config.mockBserv)
   123  	config.mockBsplit = NewMockBlockSplitter(c)
   124  	config.SetBlockSplitter(config.mockBsplit)
   125  	config.mockNotifier = NewMockNotifier(c)
   126  	config.SetNotifier(config.mockNotifier)
   127  	config.mockClock = NewMockClock(c)
   128  	config.SetClock(config.mockClock)
   129  	config.mockRekeyQueue = NewMockRekeyQueue(c)
   130  	config.SetRekeyQueue(config.mockRekeyQueue)
   131  	uhLog := config.MakeLogger("HIS")
   132  	config.SetUserHistory(kbfsedits.NewUserHistory(
   133  		uhLog, config.MakeVLogger(uhLog)))
   134  	config.observer = &FakeObserver{}
   135  	config.ctr = ctr
   136  	// turn off background flushing by default during tests
   137  	config.noBGFlush = true
   138  
   139  	config.maxNameBytes = data.MaxNameBytesDefault
   140  	config.rwpWaitTime = rekeyWithPromptWaitTimeDefault
   141  
   142  	config.SetMetadataVersion(defaultClientMetadataVer)
   143  	config.mode = modeTest{NewInitModeFromType(InitDefault)}
   144  	config.conflictResolutionDB = openCRDB(config)
   145  
   146  	config.subscriptionManagerManager = newSubscriptionManagerManager(config)
   147  	config.mockSubscriptionManagerPublisher = NewMockSubscriptionManagerPublisher(gomock.NewController(ctr.t))
   148  	config.mockSubscriptionManagerPublisher.EXPECT().PublishChange(
   149  		keybase1.SubscriptionTopic_FAVORITES).AnyTimes()
   150  	config.mockSubscriptionManagerPublisher.EXPECT().PublishChange(
   151  		keybase1.SubscriptionTopic_JOURNAL_STATUS).AnyTimes()
   152  	config.mockSubscriptionManagerPublisher.EXPECT().PublishChange(
   153  		keybase1.SubscriptionTopic_FILES_TAB_BADGE).AnyTimes()
   154  
   155  	return config
   156  }
   157  
   158  // CheckStateOnShutdown implements the Config interface for ConfigLocal.
   159  func (c *ConfigMock) CheckStateOnShutdown() bool {
   160  	return false
   161  }