Skip to content

Commit

Permalink
Database: don't return error on server.CloseDB if the db is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed May 13, 2024
1 parent d826aee commit 118aa7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ func (s *Server) CloseDB() error {
}
db, err := s.db.DB()
if err != nil {
if stderrors.Is(err, gorm.ErrInvalidDB) {
return nil
}
return errors.New(err)
}
return errors.New(db.Close())
Expand Down
11 changes: 11 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@ func TestServer(t *testing.T) {
assert.NotNil(t, server.db)
})

t.Run("CloseDB_no_error_for_invalid_db", func(t *testing.T) {
cfg := config.LoadDefault()
cfg.Set("database.config.disableAutomaticPing", true)
server, err := New(Options{Config: cfg})
require.NoError(t, err)

assert.NoError(t, server.ReplaceDB(tests.DummyDialector{})) // DummyDialector has invalid DB
require.NotNil(t, server.db)
require.NoError(t, server.CloseDB())
})

t.Run("Start", func(t *testing.T) {
cfg := config.LoadDefault()
cfg.Set("server.port", 8888)
Expand Down

0 comments on commit 118aa7b

Please sign in to comment.