From 94afd282dab1edbc2247958acebf5ee174f6ce07 Mon Sep 17 00:00:00 2001 From: Yonghwan SO Date: Sat, 24 Sep 2022 15:22:53 +0900 Subject: [PATCH] fix Connection.Close() to reset the store --- connection.go | 1 + connection_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/connection.go b/connection.go index f51fd367..1fe2253e 100644 --- a/connection.go +++ b/connection.go @@ -145,6 +145,7 @@ func (c *Connection) Close() error { if err := c.Store.Close(); err != nil { return fmt.Errorf("couldn't close connection: %w", err) } + c.Store = nil return nil } diff --git a/connection_test.go b/connection_test.go index 55c801ea..90d5614f 100644 --- a/connection_test.go +++ b/connection_test.go @@ -28,6 +28,21 @@ func Test_Connection_SimpleFlow(t *testing.T) { r.NoError(err) } +func Test_Connection_Open_Close_Reopen(t *testing.T) { + r := require.New(t) + + c, err := NewConnection(&ConnectionDetails{ + URL: "sqlite://file::memory:?_fk=true", + }) + r.NoError(err) + + for i := 0; i < 2; i++ { + r.NoError(c.Open()) + r.NoError(c.Transaction(func(c *Connection) error { return nil })) + r.NoError(c.Close()) + } +} + func Test_Connection_Open_NoDialect(t *testing.T) { r := require.New(t)