From f01e28e2391b07f7198d5d71cdb5a154fb3b1542 Mon Sep 17 00:00:00 2001 From: Michael Ackley Date: Thu, 12 Sep 2024 17:07:33 -0500 Subject: [PATCH] Adds more tests --- log/mongo/mongo_log_test.go | 32 ++++++++++++++++++++++++++++++-- log/sql/sql_log_test.go | 31 ++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/log/mongo/mongo_log_test.go b/log/mongo/mongo_log_test.go index 771db953c..720955709 100644 --- a/log/mongo/mongo_log_test.go +++ b/log/mongo/mongo_log_test.go @@ -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() { @@ -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") diff --git a/log/sql/sql_log_test.go b/log/sql/sql_log_test.go index 513371da4..c15fb3090 100644 --- a/log/sql/sql_log_test.go +++ b/log/sql/sql_log_test.go @@ -36,6 +36,9 @@ type SQLLogTestSuite struct { suite.Suite sqlLogRootPath string log *sqlLog + + settings *quickfix.Settings + sessionID quickfix.SessionID } func (suite *SQLLogTestSuite) SetupTest() { @@ -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")