Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
mongodb_backend_test.cpp File Reference
#include <gtest/gtest.h>
#include <memory>
#include <string>
#include "database/backends/mongodb_backend.h"
#include "database/core/database_backend.h"
Include dependency graph for mongodb_backend_test.cpp:

Go to the source code of this file.

Classes

class  MongoDBBackendTest
 

Functions

 TEST_F (MongoDBBackendTest, TypeReturnsMongoDB)
 
 TEST_F (MongoDBBackendTest, BackendNameIsCorrect)
 
 TEST_F (MongoDBBackendTest, InitiallyNotInitialized)
 
 TEST_F (MongoDBBackendTest, InitiallyNotInTransaction)
 
 TEST_F (MongoDBBackendTest, ExecuteQueryFailsWithoutInit)
 
 TEST_F (MongoDBBackendTest, SelectQueryFailsWithoutInit)
 
 TEST_F (MongoDBBackendTest, BeginTransactionFailsWithoutInit)
 
 TEST_F (MongoDBBackendTest, CommitTransactionFailsWithoutInit)
 
 TEST_F (MongoDBBackendTest, RollbackTransactionFailsWithoutInit)
 
 TEST_F (MongoDBBackendTest, ShutdownWithoutInitIsNoOp)
 
 TEST_F (MongoDBBackendTest, CreateReturnsValidBackend)
 
 TEST_F (MongoDBBackendTest, ConnectionInfoBeforeInit)
 
 TEST_F (MongoDBBackendTest, LastErrorBeforeInit)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 212 of file mongodb_backend_test.cpp.

213{
214 ::testing::InitGoogleTest(&argc, argv);
215 return RUN_ALL_TESTS();
216}

◆ TEST_F() [1/13]

TEST_F ( MongoDBBackendTest ,
BackendNameIsCorrect  )

Definition at line 63 of file mongodb_backend_test.cpp.

64{
65 EXPECT_STREQ(mongodb_backend::backend_name(), "mongodb_backend");
66}
static constexpr const char * backend_name()
Backend name for error messages.

References database::backends::mongodb_backend::backend_name().

Here is the call graph for this function:

◆ TEST_F() [2/13]

TEST_F ( MongoDBBackendTest ,
BeginTransactionFailsWithoutInit  )

Definition at line 98 of file mongodb_backend_test.cpp.

99{
100 auto result = backend_->begin_transaction();
101 EXPECT_FALSE(result.is_ok());
102}

◆ TEST_F() [3/13]

TEST_F ( MongoDBBackendTest ,
CommitTransactionFailsWithoutInit  )

Definition at line 104 of file mongodb_backend_test.cpp.

105{
106 auto result = backend_->commit_transaction();
107 EXPECT_FALSE(result.is_ok());
108}

◆ TEST_F() [4/13]

TEST_F ( MongoDBBackendTest ,
ConnectionInfoBeforeInit  )

Definition at line 142 of file mongodb_backend_test.cpp.

143{
144 auto info = backend_->connection_info();
145 SUCCEED();
146}
@ info
Informational messages (default)

◆ TEST_F() [5/13]

TEST_F ( MongoDBBackendTest ,
CreateReturnsValidBackend  )

Definition at line 130 of file mongodb_backend_test.cpp.

131{
132 auto backend = mongodb_backend::create();
133 ASSERT_NE(backend, nullptr);
134 EXPECT_EQ(backend->type(), database_types::mongodb);
135 EXPECT_FALSE(backend->is_initialized());
136}

◆ TEST_F() [6/13]

TEST_F ( MongoDBBackendTest ,
ExecuteQueryFailsWithoutInit  )

Definition at line 86 of file mongodb_backend_test.cpp.

87{
88 auto result = backend_->execute_query("users:{\"name\":\"John\"}");
89 EXPECT_FALSE(result.is_ok());
90}

◆ TEST_F() [7/13]

TEST_F ( MongoDBBackendTest ,
InitiallyNotInitialized  )

Definition at line 72 of file mongodb_backend_test.cpp.

73{
74 EXPECT_FALSE(backend_->is_initialized());
75}

◆ TEST_F() [8/13]

TEST_F ( MongoDBBackendTest ,
InitiallyNotInTransaction  )

Definition at line 77 of file mongodb_backend_test.cpp.

78{
79 EXPECT_FALSE(backend_->in_transaction());
80}

◆ TEST_F() [9/13]

TEST_F ( MongoDBBackendTest ,
LastErrorBeforeInit  )

Definition at line 148 of file mongodb_backend_test.cpp.

149{
150 auto error = backend_->last_error();
151 SUCCEED();
152}
VoidResult error(const std::string &msg, int code=-1)

◆ TEST_F() [10/13]

TEST_F ( MongoDBBackendTest ,
RollbackTransactionFailsWithoutInit  )

Definition at line 110 of file mongodb_backend_test.cpp.

111{
112 auto result = backend_->rollback_transaction();
113 EXPECT_FALSE(result.is_ok());
114}

◆ TEST_F() [11/13]

TEST_F ( MongoDBBackendTest ,
SelectQueryFailsWithoutInit  )

Definition at line 92 of file mongodb_backend_test.cpp.

93{
94 auto result = backend_->select_query("users:{\"name\":\"John\"}");
95 EXPECT_FALSE(result.is_ok());
96}

◆ TEST_F() [12/13]

TEST_F ( MongoDBBackendTest ,
ShutdownWithoutInitIsNoOp  )

Definition at line 120 of file mongodb_backend_test.cpp.

121{
122 auto result = backend_->shutdown();
123 EXPECT_TRUE(result.is_ok());
124}

◆ TEST_F() [13/13]

TEST_F ( MongoDBBackendTest ,
TypeReturnsMongoDB  )

Definition at line 58 of file mongodb_backend_test.cpp.

59{
60 EXPECT_EQ(backend_->type(), database_types::mongodb);
61}