github.com/Finschia/ostracon@v1.1.5/cmd/ostracon/commands/compact_test.go (about)

     1  package commands
     2  
     3  import (
     4  	cfg "github.com/Finschia/ostracon/config"
     5  	"github.com/Finschia/ostracon/libs/log"
     6  	"github.com/stretchr/testify/assert"
     7  	"os"
     8  	"testing"
     9  )
    10  
    11  func Test_RunE(t *testing.T) {
    12  	config = cfg.TestConfig()
    13  	config.RootDir = os.TempDir()
    14  	config.DBBackend = "badgerdb" // not support
    15  	logger = log.TestingLogger()
    16  	err := CompactGoLevelDBCmd.RunE(nil, nil)
    17  	assert.Error(t, err)
    18  	config.DBBackend = "goleveldb"
    19  	err = CompactGoLevelDBCmd.RunE(nil, nil)
    20  	assert.NoError(t, err)
    21  }
    22  
    23  func Test_compactGoLevelDBs(t *testing.T) {
    24  	type args struct {
    25  		rootDir string
    26  		logger  log.Logger
    27  	}
    28  	tests := []struct {
    29  		name string
    30  		args args
    31  	}{
    32  		{
    33  			name: "success",
    34  			args: args{
    35  				rootDir: os.TempDir(),
    36  				logger:  log.TestingLogger(),
    37  			},
    38  		},
    39  		{
    40  			name: "doesn't exist db dir",
    41  			args: args{
    42  				rootDir: "/nonexistent",
    43  				logger:  log.TestingLogger(),
    44  			},
    45  		},
    46  	}
    47  	for _, tt := range tests {
    48  		t.Run(tt.name, func(t *testing.T) {
    49  			compactGoLevelDBs(tt.args.rootDir, tt.args.logger)
    50  		})
    51  	}
    52  }