From c703a26c10b3954c7d22b141ad09e231be67b883 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 15 Sep 2024 12:37:42 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Load=20store=20from=20config=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- store/factory.go | 4 ++++ store/factory_test.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/store/factory.go b/store/factory.go index fbcc5c0..c6c5aa8 100644 --- a/store/factory.go +++ b/store/factory.go @@ -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) diff --git a/store/factory_test.go b/store/factory_test.go index 38568ac..9cde562 100644 --- a/store/factory_test.go +++ b/store/factory_test.go @@ -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) +}