mirror of
https://github.com/gotify/server.git
synced 2026-05-06 21:42:07 +08:00
Add health api
This commit is contained in:
6
database/ping.go
Normal file
6
database/ping.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package database
|
||||
|
||||
// Ping pings the database to verify the connection.
|
||||
func (d *GormDatabase) Ping() error {
|
||||
return d.DB.DB().Ping()
|
||||
}
|
||||
16
database/ping_test.go
Normal file
16
database/ping_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func (s *DatabaseSuite) TestPing_onValidDB() {
|
||||
err := s.db.Ping()
|
||||
assert.NoError(s.T(), err)
|
||||
}
|
||||
|
||||
func (s *DatabaseSuite) TestPing_onClosedDB() {
|
||||
s.db.Close()
|
||||
err := s.db.Ping()
|
||||
assert.Error(s.T(), err)
|
||||
}
|
||||
Reference in New Issue
Block a user