forked from TrueCloudLab/neoneo-go
docs: fix supported database types
This commit is contained in:
parent
2f5137e9b7
commit
70e59d83c9
8 changed files with 51 additions and 9 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/internal/testcli"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
@ -19,7 +20,7 @@ func TestDBRestoreDump(t *testing.T) {
|
|||
chainPath := filepath.Join(tmpDir, "neogotestchain")
|
||||
cfg, err := config.LoadFile(filepath.Join("..", "..", "config", "protocol.unit_testnet.yml"))
|
||||
require.NoError(t, err, "could not load config")
|
||||
cfg.ApplicationConfiguration.DBConfiguration.Type = "leveldb"
|
||||
cfg.ApplicationConfiguration.DBConfiguration.Type = dbconfig.LevelDB
|
||||
cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.DataDirectoryPath = chainPath
|
||||
return cfg
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/cli/server"
|
||||
"github.com/nspcc-dev/neo-go/internal/testcli"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
@ -25,7 +26,7 @@ func TestServerStart(t *testing.T) {
|
|||
saveCfg := func(t *testing.T, f func(cfg *config.Config)) string {
|
||||
cfg := *ptr
|
||||
chainPath := filepath.Join(t.TempDir(), "neogotestchain")
|
||||
cfg.ApplicationConfiguration.DBConfiguration.Type = "leveldb"
|
||||
cfg.ApplicationConfiguration.DBConfiguration.Type = dbconfig.LevelDB
|
||||
cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.DataDirectoryPath = chainPath
|
||||
f(&cfg)
|
||||
out, err := yaml.Marshal(cfg)
|
||||
|
|
|
@ -350,7 +350,7 @@ func TestInitBlockChain(t *testing.T) {
|
|||
_, err := initBlockChain(config.Config{
|
||||
ApplicationConfiguration: config.ApplicationConfiguration{
|
||||
DBConfiguration: dbconfig.DBConfiguration{
|
||||
Type: "inmemory",
|
||||
Type: dbconfig.InMemoryDB,
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
|
|
@ -53,8 +53,8 @@ DBConfiguration:
|
|||
ReadOnly: false
|
||||
```
|
||||
where:
|
||||
- `Type` is the database type (string value). Supported types: `levelDB` and
|
||||
`boltDB`.
|
||||
- `Type` is the database type (string value). Supported types: `leveldb`, `boltdb` and
|
||||
`inmemory` (not recommended for production usage).
|
||||
- `LevelDBOptions` are settings for LevelDB. Includes the DB files path and ReadOnly mode toggle.
|
||||
If ReadOnly mode is on, then an error will be returned on attempt to connect to unexisting or empty
|
||||
database. Database doesn't allow changes in this mode, a warning will be logged on DB persist attempts.
|
||||
|
|
|
@ -288,7 +288,7 @@ func TestManagement_StartFromHeight(t *testing.T) {
|
|||
// Create database to be able to start another chain from the same height later.
|
||||
ldbDir := t.TempDir()
|
||||
dbConfig := dbconfig.DBConfiguration{
|
||||
Type: "leveldb",
|
||||
Type: dbconfig.LevelDB,
|
||||
LevelDBOptions: dbconfig.LevelDBOptions{
|
||||
DataDirectoryPath: ldbDir,
|
||||
},
|
||||
|
|
11
pkg/core/storage/dbconfig/store_type.go
Normal file
11
pkg/core/storage/dbconfig/store_type.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package dbconfig
|
||||
|
||||
// Available storage types.
|
||||
const (
|
||||
// BoltDB represents Bolt DB storage name.
|
||||
BoltDB = "boltdb"
|
||||
// LevelDB represents Level DB storage name.
|
||||
LevelDB = "leveldb"
|
||||
// InMemoryDB represents in-memory storage name.
|
||||
InMemoryDB = "inmemory"
|
||||
)
|
|
@ -114,11 +114,11 @@ func NewStore(cfg dbconfig.DBConfiguration) (Store, error) {
|
|||
var store Store
|
||||
var err error
|
||||
switch cfg.Type {
|
||||
case "leveldb":
|
||||
case dbconfig.LevelDB:
|
||||
store, err = NewLevelDBStore(cfg.LevelDBOptions)
|
||||
case "inmemory":
|
||||
case dbconfig.InMemoryDB:
|
||||
store = NewMemoryStore()
|
||||
case "boltdb":
|
||||
case dbconfig.BoltDB:
|
||||
store, err = NewBoltDBStore(cfg.BoltDBOptions)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown storage: %s", cfg.Type)
|
||||
|
|
29
pkg/core/storage/store_type_test.go
Normal file
29
pkg/core/storage/store_type_test.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestStorageNames(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
cfg := dbconfig.DBConfiguration{
|
||||
LevelDBOptions: dbconfig.LevelDBOptions{
|
||||
DataDirectoryPath: filepath.Join(tmp, "level"),
|
||||
},
|
||||
BoltDBOptions: dbconfig.BoltDBOptions{
|
||||
FilePath: filepath.Join(tmp, "bolt"),
|
||||
},
|
||||
}
|
||||
for _, name := range []string{dbconfig.BoltDB, dbconfig.LevelDB, dbconfig.InMemoryDB} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
cfg.Type = name
|
||||
s, err := NewStore(cfg)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.Close())
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue