github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libkbfs/interface_test.go (about) 1 // Copyright 2017 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 "context" 9 "testing" 10 11 "github.com/keybase/client/go/kbfs/kbfscodec" 12 "github.com/keybase/client/go/kbfs/test/clocktest" 13 "github.com/keybase/client/go/kbfs/tlf" 14 "github.com/keybase/client/go/libkb" 15 "github.com/keybase/client/go/logger" 16 "github.com/keybase/client/go/protocol/keybase1" 17 ) 18 19 type testCodecGetter struct { 20 codec kbfscodec.Codec 21 } 22 23 func newTestCodecGetter() testCodecGetter { 24 return testCodecGetter{kbfscodec.NewMsgpack()} 25 } 26 27 func (cg testCodecGetter) Codec() kbfscodec.Codec { 28 return cg.codec 29 } 30 31 type testLogMaker struct { 32 log logger.Logger 33 vdebugSetting string 34 } 35 36 func newTestLogMakerWithVDebug( 37 t *testing.T, vdebugSetting string) testLogMaker { 38 return testLogMaker{logger.NewTestLogger(t), vdebugSetting} 39 } 40 41 func newTestLogMaker(t *testing.T) testLogMaker { 42 return newTestLogMakerWithVDebug(t, "") 43 } 44 45 func (lm testLogMaker) MakeLogger(_ string) logger.Logger { 46 return lm.log 47 } 48 49 func (lm testLogMaker) MakeVLogger(log logger.Logger) *libkb.VDebugLog { 50 vlog := libkb.NewVDebugLog(log) 51 vlog.Configure(lm.vdebugSetting) 52 return vlog 53 } 54 55 func (lm testLogMaker) GetPerfLog() logger.Logger { 56 return lm.log 57 } 58 59 type testClockGetter struct { 60 clock *clocktest.TestClock 61 } 62 63 var _ clockGetter = (*testClockGetter)(nil) 64 65 func newTestClockGetter() *testClockGetter { 66 return &testClockGetter{clocktest.NewTestClockNow()} 67 } 68 69 func (cg *testClockGetter) Clock() Clock { 70 return cg.clock 71 } 72 73 func (cg *testClockGetter) TestClock() *clocktest.TestClock { 74 return cg.clock 75 } 76 77 type testSyncedTlfGetterSetter struct { 78 syncedTlfs map[tlf.ID]FolderSyncConfig 79 } 80 81 var _ syncedTlfGetterSetter = (*testSyncedTlfGetterSetter)(nil) 82 83 func newTestSyncedTlfGetterSetter() *testSyncedTlfGetterSetter { 84 return &testSyncedTlfGetterSetter{ 85 syncedTlfs: make(map[tlf.ID]FolderSyncConfig), 86 } 87 } 88 89 func (t *testSyncedTlfGetterSetter) GetTlfSyncState( 90 tlfID tlf.ID) FolderSyncConfig { 91 return t.syncedTlfs[tlfID] 92 } 93 94 func (t *testSyncedTlfGetterSetter) IsSyncedTlf(tlfID tlf.ID) bool { 95 return t.syncedTlfs[tlfID].Mode == keybase1.FolderSyncMode_ENABLED 96 } 97 98 func (t *testSyncedTlfGetterSetter) IsSyncedTlfPath(tlfPath string) bool { 99 for _, config := range t.syncedTlfs { 100 if config.TlfPath == tlfPath { 101 return true 102 } 103 } 104 return false 105 } 106 107 func (t *testSyncedTlfGetterSetter) SetTlfSyncState( 108 _ context.Context, tlfID tlf.ID, 109 config FolderSyncConfig) (<-chan error, error) { 110 t.syncedTlfs[tlfID] = config 111 return nil, nil 112 } 113 114 func (t *testSyncedTlfGetterSetter) GetAllSyncedTlfs() []tlf.ID { 115 tlfs := make([]tlf.ID, 0, len(t.syncedTlfs)) 116 for tlf := range t.syncedTlfs { 117 tlfs = append(tlfs, tlf) 118 } 119 return tlfs 120 } 121 122 func (t *testSyncedTlfGetterSetter) OfflineAvailabilityForPath( 123 tlfPath string) keybase1.OfflineAvailability { 124 if t.IsSyncedTlfPath(tlfPath) { 125 return keybase1.OfflineAvailability_BEST_EFFORT 126 } 127 return keybase1.OfflineAvailability_NONE 128 } 129 130 func (t *testSyncedTlfGetterSetter) OfflineAvailabilityForID( 131 tlfID tlf.ID) keybase1.OfflineAvailability { 132 if t.IsSyncedTlf(tlfID) { 133 return keybase1.OfflineAvailability_BEST_EFFORT 134 } 135 return keybase1.OfflineAvailability_NONE 136 } 137 138 type testInitModeGetter struct { 139 mode InitModeType 140 } 141 142 var _ initModeGetter = (*testInitModeGetter)(nil) 143 144 func (t testInitModeGetter) Mode() InitMode { 145 return modeTest{NewInitModeFromType(t.mode)} 146 } 147 148 func (t testInitModeGetter) IsTestMode() bool { 149 return true 150 }