// NewTestKV returns a KV store for testing purposes.
NewTestKV returns a KV store for testing purposes.
// NewTestKV returns a KV store for testing purposes .
func NewTestKV(kv string, path string, opts ...TestKVOption) (KV, func(), error) {
	cfg := defaultKVConfig()
	for _, opt := range opts {
		opt(&cfg)
	}
	switch kv {
	case "inmem":
		inmemdb := NewInmem()
		return inmemdb, func() { _ = inmemdb.Close() }, nil
	case "level": 
		if cfg.RemoveExisting {
			_ = os.RemoveAll(path)
		}
		leveldb, err := NewLevelDB(path)
		if err != nil {
			return nil, nil, err
		}
		cleanup := func() {
			_ = leveldb.Close()
			if cfg.RemoveExisting {
				_ = os.RemoveAll(path)
			}
		}
		return leveldb, cleanup, nil
	case "badger": 
		if cfg.RemoveExisting {
			_ = os.RemoveAll(path)
		}
		badger, err := NewBadger(path)
		if err != nil {
			return nil, nil, err
		}
		cleanup := func() {
			_ = badger.Close()
			if cfg.RemoveExisting {
				_ = os.RemoveAll(path)
			}
		}
		return badger, cleanup, nil
	default:
		return nil, nil, fmt.Errorf("unknown kv %s", kv)
	}
}
func NewTestKV ( kv string , path string , opts ... TestKVOption ) ( KV , func ( ) , error ) { cfg := defaultKVConfig ( ) for _ , opt := range opts { opt ( & cfg ) } switch kv { case " " : inmemdb := NewInmem ( ) return inmemdb , func ( ) { _ = inmemdb . Close ( ) } , nil case " " : if cfg . RemoveExisting { _ = os . RemoveAll ( path ) } leveldb , err := NewLevelDB ( path ) if err != nil { return nil , nil , err } cleanup := func ( ) { _ = leveldb . Close ( ) if cfg . RemoveExisting { _ = os . RemoveAll ( path ) } } return leveldb , cleanup , nil case " " : if cfg . RemoveExisting { _ = os . RemoveAll ( path ) } badger , err := NewBadger ( path ) if err != nil { return nil , nil , err } cleanup := func ( ) { _ = badger . Close ( ) if cfg . RemoveExisting { _ = os . RemoveAll ( path ) } } return badger , cleanup , nil default : return nil , nil , fmt . Errorf ( " " , kv ) } }
NewTestKV returns a KV store for testing purposes.
NewTestKV returns a KV store for testing purposes .
//nolint:goconst // nolint:goconst