Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dbs no one uses #116

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 90 additions & 28 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,113 @@
linters:
run:
tests: true
timeout: 10m

linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- exportloopref
- errcheck
- gci
- goconst
- gocritic
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- staticcheck
- thelper
- typecheck
- stylecheck
- revive
- typecheck
- tenv
- unconvert
# Prefer unparam over revive's unused param. It is more thorough in its checking.
- unparam
- unused
- nolintlint
- misspell

issues:
exclude-rules:
- text: 'differs only by capitalization to method'
linters:
- revive
- text: 'Use of weak random number generator'
linters:
- gosec
- linters:
- staticcheck
text: "SA1019:" # silence errors on usage of deprecated funcs

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
errcheck:
check-blank: true
depguard:
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- blank # blank imports
- dot # dot imports
- prefix(github.com/cometbft/cometbft-db)
custom-order: true
revive:
enable-all-rules: true
# Do NOT whine about the following, full explanation found in:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#description-of-available-rules
rules:
main:
files:
- $all
- "!$test"
allow:
- $gostd
- github.com/cometbft
- github.com/syndtr/goleveldb/leveldb
- github.com/google/btree
test:
files:
- $test
allow:
- $gostd
- github.com/cometbft
- github.com/syndtr/goleveldb/leveldb
- github.com/stretchr/testify
- name: use-any
disabled: true
- name: if-return
disabled: true
- name: max-public-structs
disabled: true
- name: cognitive-complexity
disabled: true
- name: argument-limit
disabled: true
- name: cyclomatic
disabled: true
- name: file-header
disabled: true
- name: function-length
disabled: true
- name: function-result-limit
disabled: true
- name: line-length-limit
disabled: true
- name: flag-parameter
disabled: true
- name: add-constant
disabled: true
- name: empty-lines
disabled: true
- name: banned-characters
disabled: true
- name: deep-exit
disabled: true
- name: confusing-results
disabled: true
- name: unused-parameter
disabled: true
- name: modifies-value-receiver
disabled: true
- name: early-return
disabled: true
- name: confusing-naming
disabled: true
- name: defer
disabled: true
# Disabled in favour of unparam.
- name: unused-parameter
disabled: true
- name: unhandled-error
disabled: false
arguments:
- 'fmt.Printf'
- 'fmt.Print'
- 'fmt.Println'
- 'myFunction'
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ test-badgerdb:
@go test $(PACKAGES) -tags badgerdb -v
.PHONY: test-badgerdb

test-pebble:
@echo "--> Running go test"
@go test $(PACKAGES) -tags pebbledb -v

test-all:
@echo "--> Running go test"
@go test $(PACKAGES) -tags cleveldb,boltdb,rocksdb,grocksdb_clean_link,badgerdb -v
Expand All @@ -54,7 +58,7 @@ test-all-with-coverage:
-race \
-coverprofile=coverage.txt \
-covermode=atomic \
-tags=memdb,goleveldb,cleveldb,boltdb,rocksdb,grocksdb_clean_link,badgerdb \
-tags=memdb,goleveldb,cleveldb,boltdb,rocksdb,grocksdb_clean_link,badgerdb,pebbledb \
-v
.PHONY: test-all-with-coverage

Expand Down
20 changes: 16 additions & 4 deletions backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// Register a test backend for PrefixDB as well, with some unrelated junk data
func init() {
//nolint: errcheck
//nolint: errcheck, revive // probably should check errors?
registerDBCreator("prefixdb", func(name, dir string) (DB, error) {
mdb := NewMemDB()
mdb.Set([]byte("a"), []byte{1})
Expand All @@ -22,7 +22,7 @@ func init() {
mdb.Set([]byte("u"), []byte{21})
mdb.Set([]byte("z"), []byte{26})
return NewPrefixDB(mdb, []byte("test/")), nil
}, false)
})
}

func cleanupDBDir(dir, name string) {
Expand All @@ -33,6 +33,7 @@ func cleanupDBDir(dir, name string) {
}

func testBackendGetSetDelete(t *testing.T, backend BackendType) {
t.Helper()
// Default
dirname, err := os.MkdirTemp("", fmt.Sprintf("test_backend_%s_", backend))
require.Nil(t, err)
Expand Down Expand Up @@ -161,6 +162,8 @@ func TestDBIterator(t *testing.T) {
}

func testDBIterator(t *testing.T, backend BackendType) {
t.Helper()

name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
db, err := NewDB(name, backend, dir)
Expand Down Expand Up @@ -317,6 +320,8 @@ func testDBIterator(t *testing.T, backend BackendType) {
}

func verifyIterator(t *testing.T, itr Iterator, expected []int64, msg string) {
t.Helper()

var list []int64
for itr.Valid() {
key := itr.Key()
Expand All @@ -335,6 +340,8 @@ func TestDBBatch(t *testing.T) {
}

func testDBBatch(t *testing.T, backend BackendType) {
t.Helper()

name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
db, err := NewDB(name, backend, dir)
Expand Down Expand Up @@ -396,8 +403,12 @@ func testDBBatch(t *testing.T, backend BackendType) {

// it should be possible to close an empty batch, and to re-close a closed batch
batch = db.NewBatch()
batch.Close()
batch.Close()
if err := batch.Close(); err != nil {
require.NoError(t, err)
}
if err := batch.Close(); err != nil {
require.NoError(t, err)
}

// all other operations on a closed batch should error
require.Error(t, batch.Set([]byte("a"), []byte{9}))
Expand All @@ -407,6 +418,7 @@ func testDBBatch(t *testing.T, backend BackendType) {
}

func assertKeyValues(t *testing.T, db DB, expect map[string][]byte) {
t.Helper()
iter, err := db.Iterator(nil, nil)
require.NoError(t, err)
defer iter.Close()
Expand Down
Loading
Loading