Skip to content

Commit

Permalink
Added an extra nil checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Marian Craciunescu committed Jun 3, 2016
1 parent fad4902 commit c07320f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (router *router) Stop() error {
}

func (router *router) Check() error {
if router.messageStore == nil || router.kvStore == nil {
return ErrServiceNotProvided
}

err := router.messageStore.Check()
if err != nil {
return err
Expand Down
6 changes: 5 additions & 1 deletion server/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ func TestRouter_Check(t *testing.T) {
// Given a Multiplexer with route
router, _ := aRouterRoute(1)

//first the messageStore and kvStore will be nil
err := router.Check()
a.NotNil(err)

// mock messageStore
msMock := NewMockMessageStore(ctrl)
router.messageStore = msMock
Expand All @@ -408,7 +412,7 @@ func TestRouter_Check(t *testing.T) {
msMock.EXPECT().Check().Return(nil)
mockKvStore.EXPECT().Check().Return(nil)
//both router health checks will work
err := router.Check()
err = router.Check()
a.Nil(err)

//router messageStore will return error
Expand Down
5 changes: 5 additions & 0 deletions store/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
_ "github.com/mattn/go-sqlite3"

"fmt"
"github.com/vektra/errors"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -164,6 +165,10 @@ func (kvStore *SqliteKVStore) Open() error {
}

func (kvStore *SqliteKVStore) Check() error {
if kvStore.db == nil {
protocol.Err("Db pointer is not initialized")
return errors.New("Db service is null.")
}

if err := kvStore.db.DB().Ping(); err != nil {
protocol.Err("error pinging database %q: %q", kvStore.filename, err.Error())
Expand Down

0 comments on commit c07320f

Please sign in to comment.