Skip to content

Commit

Permalink
fix Connection.Close() to reset the store
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Sep 24, 2022
1 parent 98751a9 commit b0c857d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions connection.go
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions connection_test.go
Expand Up @@ -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)

Expand Down

0 comments on commit b0c857d

Please sign in to comment.