Skip to content

Commit

Permalink
Adds more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ackleymi committed Sep 20, 2024
1 parent 9c5d08c commit f01e28e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
32 changes: 30 additions & 2 deletions log/mongo/mongo_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
// MongoLogTestSuite runs tests for the MongoLog impl of Log.
type MongoLogTestSuite struct {
suite.Suite
log *mongoLog
log *mongoLog
settings *quickfix.Settings
sessionID quickfix.SessionID
}

func (suite *MongoLogTestSuite) SetupTest() {
Expand All @@ -57,13 +59,39 @@ SenderCompID=%s
TargetCompID=%s`, mongoDbCxn, mongoDatabase, mongoReplicaSet, sessionID.BeginString, sessionID.SenderCompID, sessionID.TargetCompID)))
require.Nil(suite.T(), err)

suite.sessionID = sessionID
suite.settings = settings
}

func (suite *MongoLogTestSuite) TestMongoLogNoSession() {
// create log
log, err := NewLogFactory(settings).CreateSessionLog(sessionID)
log, err := NewLogFactory(suite.settings).Create()
require.Nil(suite.T(), err)
suite.log = log.(*mongoLog)

suite.log.OnIncoming([]byte("Cool1"))
suite.log.OnOutgoing([]byte("Cool2"))
entries, err := suite.log.getEntries("messages_log")
require.Nil(suite.T(), err)
require.Len(suite.T(), entries, 2)
require.Equal(suite.T(), "Cool1", entries[0])
require.Equal(suite.T(), "Cool2", entries[1])

suite.log.OnEvent("Cool3")
suite.log.OnEvent("Cool4")
entries, err = suite.log.getEntries("event_log")
require.Nil(suite.T(), err)
require.Len(suite.T(), entries, 2)
require.Equal(suite.T(), "Cool3", entries[0])
require.Equal(suite.T(), "Cool4", entries[1])
}

func (suite *MongoLogTestSuite) TestMongoLog() {
// create log
log, err := NewLogFactory(suite.settings).CreateSessionLog(suite.sessionID)
require.Nil(suite.T(), err)
suite.log = log.(*mongoLog)

suite.log.OnIncoming([]byte("Cool1"))
suite.log.OnOutgoing([]byte("Cool2"))
entries, err := suite.log.getEntries("messages_log")
Expand Down
31 changes: 30 additions & 1 deletion log/sql/sql_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type SQLLogTestSuite struct {
suite.Suite
sqlLogRootPath string
log *sqlLog

settings *quickfix.Settings
sessionID quickfix.SessionID
}

func (suite *SQLLogTestSuite) SetupTest() {
Expand Down Expand Up @@ -71,13 +74,39 @@ SenderCompID=%s
TargetCompID=%s`, sqlDriver, sqlDsn, sessionID.BeginString, sessionID.SenderCompID, sessionID.TargetCompID)))
require.Nil(suite.T(), err)

suite.sessionID = sessionID
suite.settings = settings
}

func (suite *SQLLogTestSuite) TestSQLLogNoSession() {
// create log
log, err := NewLogFactory(settings).CreateSessionLog(sessionID)
log, err := NewLogFactory(suite.settings).Create()
require.Nil(suite.T(), err)
suite.log = log.(*sqlLog)

suite.log.OnIncoming([]byte("Cool1"))
suite.log.OnOutgoing([]byte("Cool2"))
entries, err := suite.log.getEntries("messages_log")
require.Nil(suite.T(), err)
require.Len(suite.T(), entries, 2)
require.Equal(suite.T(), "Cool1", entries[0])
require.Equal(suite.T(), "Cool2", entries[1])

suite.log.OnEvent("Cool3")
suite.log.OnEvent("Cool4")
entries, err = suite.log.getEntries("event_log")
require.Nil(suite.T(), err)
require.Len(suite.T(), entries, 2)
require.Equal(suite.T(), "Cool3", entries[0])
require.Equal(suite.T(), "Cool4", entries[1])
}

func (suite *SQLLogTestSuite) TestSQLLog() {
// create log
log, err := NewLogFactory(suite.settings).CreateSessionLog(suite.sessionID)
require.Nil(suite.T(), err)
suite.log = log.(*sqlLog)

suite.log.OnIncoming([]byte("Cool1"))
suite.log.OnOutgoing([]byte("Cool2"))
entries, err := suite.log.getEntries("messages_log")
Expand Down

0 comments on commit f01e28e

Please sign in to comment.