github.com/ethersphere/bee/v2@v2.2.0/pkg/feeds/sequence/lookup_test.go (about)

     1  // Copyright 2021 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package sequence_test
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/ethersphere/bee/v2/pkg/crypto"
    11  	"github.com/ethersphere/bee/v2/pkg/feeds"
    12  	"github.com/ethersphere/bee/v2/pkg/feeds/sequence"
    13  	feedstesting "github.com/ethersphere/bee/v2/pkg/feeds/testing"
    14  	storage "github.com/ethersphere/bee/v2/pkg/storage"
    15  )
    16  
    17  func TestFinder(t *testing.T) {
    18  	t.Parallel()
    19  
    20  	testf := func(t *testing.T, finderf func(storage.Getter, *feeds.Feed) feeds.Lookup, updaterf func(putter storage.Putter, signer crypto.Signer, topic []byte) (feeds.Updater, error)) {
    21  		t.Helper()
    22  
    23  		t.Run("basic", func(t *testing.T) {
    24  			feedstesting.TestFinderBasic(t, finderf, updaterf)
    25  		})
    26  
    27  		t.Run("fixed", func(t *testing.T) {
    28  			i := 0
    29  			nextf := func() (bool, int64) {
    30  				i++
    31  				return i == 40, int64(i)
    32  			}
    33  			feedstesting.TestFinderFixIntervals(t, nextf, finderf, updaterf)
    34  		})
    35  
    36  		t.Run("random", func(t *testing.T) {
    37  			feedstesting.TestFinderRandomIntervals(t, finderf, updaterf)
    38  		})
    39  	}
    40  
    41  	t.Run("sync", func(t *testing.T) {
    42  		t.Parallel()
    43  		testf(t, sequence.NewFinder, sequence.NewUpdater)
    44  	})
    45  
    46  	t.Run("async", func(t *testing.T) {
    47  		t.Parallel()
    48  		testf(t, sequence.NewAsyncFinder, sequence.NewUpdater)
    49  	})
    50  }