From c8762cfea4672eaf3670a132c3b37f2aba978a73 Mon Sep 17 00:00:00 2001 From: Maksim Konovalov Date: Fri, 30 Aug 2024 15:53:49 +0300 Subject: [PATCH] feature/tests: fixes after review --- discovery.go | 3 --- discovery_test.go | 14 -------------- vshard_shadow_test.go | 11 ++++------- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/discovery.go b/discovery.go index 907d490..a08e7b9 100644 --- a/discovery.go +++ b/discovery.go @@ -171,9 +171,6 @@ func (r *Router) DiscoveryAllBuckets(ctx context.Context) error { errGr, ctx := errgroup.WithContext(ctx) idToReplicasetRef := r.getIDToReplicaset() - if idToReplicasetRef == nil { - return fmt.Errorf("smth went wrong; replicasets map is empty") - } for _, rs := range idToReplicasetRef { rs := rs diff --git a/discovery_test.go b/discovery_test.go index 98f10f7..c93af5e 100644 --- a/discovery_test.go +++ b/discovery_test.go @@ -36,20 +36,6 @@ func TestSearchLock_WaitOnSearch(t *testing.T) { require.True(t, time.Since(lockStart) < 12*time.Millisecond && time.Since(lockStart) > 9*time.Millisecond) } -func TestRouter_DiscoveryAllBuckets(t *testing.T) { - ctx := context.TODO() - - r := Router{ - cfg: Config{ - TotalBucketCount: uint64(256000), - Logger: &EmptyLogger{}, - }, - } - - err := r.DiscoveryAllBuckets(ctx) - require.Error(t, err) // replicaset map is empty -} - func TestRouter_BucketResolve_InvalidBucketID(t *testing.T) { ctx := context.TODO() diff --git a/vshard_shadow_test.go b/vshard_shadow_test.go index 4a86e44..3aed0b3 100644 --- a/vshard_shadow_test.go +++ b/vshard_shadow_test.go @@ -12,21 +12,18 @@ import ( "github.com/KaymeKaydex/go-vshard-router/providers/static" ) -// Check that ErrorTopologyProvider implements TopologyProvider interface -var _ vshardrouter.TopologyProvider = (*ErrorTopologyProvider)(nil) +type errorTopologyProvider struct{} -type ErrorTopologyProvider struct{} - -func (e *ErrorTopologyProvider) Init(_ vshardrouter.TopologyController) error { +func (e *errorTopologyProvider) Init(_ vshardrouter.TopologyController) error { return fmt.Errorf("test error") } -func (e *ErrorTopologyProvider) Close() {} +func (e *errorTopologyProvider) Close() {} func TestNewRouter_ProviderError(t *testing.T) { ctx := context.TODO() _, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{ TotalBucketCount: 256000, - TopologyProvider: &ErrorTopologyProvider{}, + TopologyProvider: &errorTopologyProvider{}, }) require.ErrorIs(t, err, vshardrouter.ErrTopologyProvider)