Skip to content

Commit 3db3468

Browse files
authored
Merge pull request #19052 from aladesawe/server-auth-unexported-return
server: fix unexported-return lint issue
2 parents 8e0ea34 + db05dea commit 3db3468

File tree

7 files changed

+25
-15
lines changed

7 files changed

+25
-15
lines changed

server/auth/store.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import (
3636
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
3737
)
3838

39+
var _ AuthStore = (*authStore)(nil)
40+
3941
var (
4042
rootPerm = authpb.Permission{PermType: authpb.READWRITE, Key: []byte{}, RangeEnd: []byte{0}}
4143

@@ -938,7 +940,7 @@ func (as *authStore) IsAuthEnabled() bool {
938940
}
939941

940942
// NewAuthStore creates a new AuthStore.
941-
func NewAuthStore(lg *zap.Logger, be AuthBackend, tp TokenProvider, bcryptCost int) *authStore {
943+
func NewAuthStore(lg *zap.Logger, be AuthBackend, tp TokenProvider, bcryptCost int) AuthStore {
942944
if lg == nil {
943945
lg = zap.NewNop()
944946
}

server/auth/store_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ func setupAuthStore(t *testing.T) (store *authStore, teardownfunc func(t *testin
113113

114114
// The UserAdd function cannot generate old etcd version user data (user's option is nil)
115115
// add special users through the underlying interface
116-
addUserWithNoOption(as)
116+
asImpl, ok := as.(*authStore)
117+
require.Truef(t, ok, "addUserWithNoOption: needs an AuthStore implementation")
118+
addUserWithNoOption(asImpl)
117119

118120
tearDown := func(_ *testing.T) {
119121
as.Close()
120122
}
121-
return as, tearDown
123+
return asImpl, tearDown
122124
}
123125

124126
func addUserWithNoOption(as *authStore) {
@@ -133,7 +135,7 @@ func addUserWithNoOption(as *authStore) {
133135
as.refreshRangePermCache(tx)
134136
}
135137

136-
func enableAuthAndCreateRoot(as *authStore) error {
138+
func enableAuthAndCreateRoot(as AuthStore) error {
137139
_, err := as.UserAdd(&pb.AuthUserAddRequest{Name: "root", HashedPassword: encodePassword("root"), Options: &authpb.UserAddOptions{NoPassword: false}})
138140
if err != nil {
139141
return err

server/etcdserver/adapters.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type serverVersionAdapter struct {
3333
*EtcdServer
3434
}
3535

36-
func NewServerVersionAdapter(s *EtcdServer) *serverVersionAdapter {
36+
func NewServerVersionAdapter(s *EtcdServer) serverversion.Server {
3737
return &serverVersionAdapter{
3838
EtcdServer: s,
3939
}

server/storage/mvcc/kvstore.go

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type store struct {
8282

8383
// NewStore returns a new store. It is useful to create a store inside
8484
// mvcc pkg. It should only be used for testing externally.
85+
// revive:disable-next-line:unexported-return this is used internally in the mvcc pkg
8586
func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfig) *store {
8687
if lg == nil {
8788
lg = zap.NewNop()

server/storage/mvcc/watchable_store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var _ WatchableKV = (*watchableStore)(nil)
7676
// cancel operations.
7777
type cancelFunc func()
7878

79-
func New(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfig) *watchableStore {
79+
func New(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfig) WatchableKV {
8080
s := newWatchableStore(lg, b, le, cfg)
8181
s.wg.Add(2)
8282
go s.syncWatchersLoop()

server/storage/mvcc/watchable_store_test.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestWatch(t *testing.T) {
4444
defer w.Close()
4545

4646
w.Watch(0, testKey, nil, 0)
47-
if !s.synced.contains(string(testKey)) {
47+
if !s.(*watchableStore).synced.contains(string(testKey)) {
4848
// the key must have had an entry in synced
4949
t.Errorf("existence = false, want true")
5050
}
@@ -67,7 +67,7 @@ func TestNewWatcherCancel(t *testing.T) {
6767
t.Error(err)
6868
}
6969

70-
if s.synced.contains(string(testKey)) {
70+
if s.(*watchableStore).synced.contains(string(testKey)) {
7171
// the key shoud have been deleted
7272
t.Errorf("existence = true, want false")
7373
}
@@ -340,7 +340,9 @@ func TestWatchNoEventLossOnCompact(t *testing.T) {
340340
require.NoError(t, err)
341341
}
342342
// fill up w.Chan() with 1 buf via 2 compacted watch response
343-
s.syncWatchers([]mvccpb.Event{})
343+
sImpl, ok := s.(*watchableStore)
344+
require.Truef(t, ok, "TestWatchNoEventLossOnCompact: needs a WatchableKV implementation")
345+
sImpl.syncWatchers([]mvccpb.Event{})
344346

345347
for len(watchers) > 0 {
346348
resp := <-w.Chan()
@@ -355,7 +357,7 @@ func TestWatchNoEventLossOnCompact(t *testing.T) {
355357
require.Equalf(t, nextRev, ev.Kv.ModRevision, "got event revision %d but want %d for watcher with watch ID %d", ev.Kv.ModRevision, nextRev, resp.WatchID)
356358
nextRev++
357359
}
358-
if nextRev == s.rev()+1 {
360+
if nextRev == sImpl.rev()+1 {
359361
delete(watchers, resp.WatchID)
360362
}
361363
}
@@ -566,10 +568,13 @@ func TestWatchBatchUnsynced(t *testing.T) {
566568
}
567569
assert.Equal(t, tc.expectRevisionBatches, revisionBatches)
568570

569-
s.store.revMu.Lock()
570-
defer s.store.revMu.Unlock()
571-
assert.Equal(t, 1, s.synced.size())
572-
assert.Equal(t, 0, s.unsynced.size())
571+
sImpl, ok := s.(*watchableStore)
572+
require.Truef(t, ok, "TestWatchBatchUnsynced: needs a WatchableKV implementation")
573+
574+
sImpl.store.revMu.Lock()
575+
defer sImpl.store.revMu.Unlock()
576+
assert.Equal(t, 1, sImpl.synced.size())
577+
assert.Equal(t, 0, sImpl.unsynced.size())
573578
})
574579
}
575580
}

server/storage/schema/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type authBackend struct {
4040

4141
var _ auth.AuthBackend = (*authBackend)(nil)
4242

43-
func NewAuthBackend(lg *zap.Logger, be backend.Backend) *authBackend {
43+
func NewAuthBackend(lg *zap.Logger, be backend.Backend) auth.AuthBackend {
4444
return &authBackend{
4545
be: be,
4646
lg: lg,

0 commit comments

Comments
 (0)