github.com/ethersphere/bee/v2@v2.2.0/pkg/statestore/storeadapter/storeadapter_test.go (about)

     1  // Copyright 2023 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 storeadapter_test
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/ethersphere/bee/v2/pkg/statestore/storeadapter"
    11  	"github.com/ethersphere/bee/v2/pkg/statestore/test"
    12  	"github.com/ethersphere/bee/v2/pkg/storage"
    13  	"github.com/ethersphere/bee/v2/pkg/storage/inmemstore"
    14  	"github.com/ethersphere/bee/v2/pkg/storage/leveldbstore"
    15  )
    16  
    17  func TestStateStoreAdapter(t *testing.T) {
    18  	t.Parallel()
    19  
    20  	test.Run(t, func(t *testing.T) storage.StateStorer {
    21  		t.Helper()
    22  
    23  		store, err := storeadapter.NewStateStorerAdapter(inmemstore.New())
    24  		if err != nil {
    25  			t.Fatal(err)
    26  		}
    27  		t.Cleanup(func() {
    28  			if err := store.Close(); err != nil {
    29  				t.Fatal(err)
    30  			}
    31  		})
    32  
    33  		return store
    34  	})
    35  
    36  	test.RunPersist(t, func(t *testing.T, dir string) storage.StateStorer {
    37  		t.Helper()
    38  
    39  		leveldb, err := leveldbstore.New(dir, nil)
    40  		if err != nil {
    41  			t.Fatal(err)
    42  		}
    43  
    44  		store, err := storeadapter.NewStateStorerAdapter(leveldb)
    45  		if err != nil {
    46  			t.Fatal(err)
    47  		}
    48  
    49  		return store
    50  	})
    51  }