Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Revert "Make database optional (#72)"

This reverts commit 3fa3648.
  • Loading branch information
cammellos committed Sep 26, 2019
1 parent 1e2e007 commit cc44ddb7ce44a4203f1af444bcb5f9af3331cdb1
Showing with 7 additions and 32 deletions.
  1. +7 −10 messenger.go
  2. +0 −22 messenger_test.go
@@ -235,25 +235,22 @@ func NewMessenger(
}
}

var err error

// Configure the database.
database := c.db
if database == nil && c.dbConfig != (dbConfig{}) {
if c.db == nil && c.dbConfig == (dbConfig{}) {
return nil, errors.New("database instance or database path needs to be provided")
}
if c.db == nil {
logger.Info("opening a database", zap.String("dbPath", c.dbConfig.dbPath))
var err error
database, err = sqlite.Open(c.dbConfig.dbPath, c.dbConfig.dbKey)
if err != nil {
return nil, errors.Wrap(err, "failed to initialize database from the db config")
}
} else {
logger.Info("using in-memory database")
database, err = sqlite.Open(":memory:", "")
if err != nil {
return nil, errors.Wrap(err, "failed to initialize in-memory database")
}
}

// Apply migrations for all components.
err = sqlite.Migrate(database)
err := sqlite.Migrate(database)
if err != nil {
return nil, errors.Wrap(err, "failed to apply migrations")
}
@@ -100,28 +100,6 @@ func (s *MessengerSuite) TearDownTest() {
_ = s.logger.Sync()
}

func (s *MessengerSuite) TestInMemoryDatabase() {
key, err := crypto.GenerateKey()
s.Require().NoError(err)
m, err := NewMessenger(
key,
s.shh,
"installation-1",
)
s.Require().NoError(err)
// Verify the in-memory database works.
err = m.persistence.SaveChat(Chat{
ID: "abc",
Name: "abc",
Active: true,
ChatType: ChatTypePublic,
})
s.Require().NoError(err)
result, err := m.persistence.Chats()
s.Require().NoError(err)
s.Require().Len(result, 1)
}

func (s *MessengerSuite) TestInit() {
testCases := []struct {
Name string

0 comments on commit cc44ddb

Please sign in to comment.
You can’t perform that action at this time.