Load store from config name

This commit is contained in:
Dan Jones 2024-09-15 12:37:42 -05:00
commit c703a26c10
2 changed files with 14 additions and 0 deletions

View file

@ -26,6 +26,10 @@ func GetFactory(name string) StoreFactory {
}
func MakeStore(name string, conf config.Config) (Store, error) {
if name == "" {
name = conf.Conn.Store
}
f, ok := factories[name]
if !ok {
return nil, fmt.Errorf("%w: %s", ErrNoFactory, name)

View file

@ -45,3 +45,13 @@ func TestMakeStoreNoError(t *testing.T) {
assert.NotNil(t, s)
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)
}