✨ Load store from config name
This commit is contained in:
parent
25ed67b2e9
commit
c703a26c10
2 changed files with 14 additions and 0 deletions
|
|
@ -26,6 +26,10 @@ func GetFactory(name string) StoreFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeStore(name string, conf config.Config) (Store, error) {
|
func MakeStore(name string, conf config.Config) (Store, error) {
|
||||||
|
if name == "" {
|
||||||
|
name = conf.Conn.Store
|
||||||
|
}
|
||||||
|
|
||||||
f, ok := factories[name]
|
f, ok := factories[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("%w: %s", ErrNoFactory, name)
|
return nil, fmt.Errorf("%w: %s", ErrNoFactory, name)
|
||||||
|
|
|
||||||
|
|
@ -45,3 +45,13 @@ func TestMakeStoreNoError(t *testing.T) {
|
||||||
assert.NotNil(t, s)
|
assert.NotNil(t, s)
|
||||||
assert.NoError(t, e)
|
assert.NoError(t, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMakeStoreNoName(t *testing.T) {
|
||||||
|
AddFactory("mock", f)
|
||||||
|
defer delete(factories, "mock")
|
||||||
|
s, e := MakeStore("", config.Config{
|
||||||
|
Conn: config.ConnSettings{Store: "mock"},
|
||||||
|
})
|
||||||
|
assert.NotNil(t, s)
|
||||||
|
assert.NoError(t, e)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue