Skip to content

Commit

Permalink
(fixup) Add compact_test for improving coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tnasu committed Jul 13, 2023
1 parent b26aa05 commit c27aeef
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions cmd/ostracon/commands/compact_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package commands

import (
cfg "github.com/Finschia/ostracon/config"
"github.com/Finschia/ostracon/libs/log"
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func Test_RunE(t *testing.T) {
config = cfg.TestConfig()
config.RootDir = os.TempDir()
config.DBBackend = "badgerdb" // not support
logger = log.TestingLogger()
err := CompactGoLevelDBCmd.RunE(nil, nil)
assert.Error(t, err)
config.DBBackend = "goleveldb"
err = CompactGoLevelDBCmd.RunE(nil, nil)
assert.NoError(t, err)
}

func Test_compactGoLevelDBs(t *testing.T) {
type args struct {
rootDir string
logger log.Logger
}
tests := []struct {
name string
args args
}{
{
name: "success",
args: args{
rootDir: os.TempDir(),
logger: log.TestingLogger(),
},
},
{
name: "doesn't exist db dir",
args: args{
rootDir: "/nonexistent",
logger: log.TestingLogger(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
compactGoLevelDBs(tt.args.rootDir, tt.args.logger)
})
}
}

0 comments on commit c27aeef

Please sign in to comment.