-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
created a test class header for database api #1048
base: 1045-bug-fix
Are you sure you want to change the base?
Conversation
Reviewer's Guide by SourceryThis PR introduces a new test class header for the DatabaseAPI and modifies the access level of some DatabaseAPI methods to support testing. The implementation creates a new TestDatabaseAPI class that will be used for testing database operations, and changes the access modifiers in the original DatabaseAPI class to allow the test class to access necessary methods. Class diagram for DatabaseAPI and TestDatabaseAPIclassDiagram
class DatabaseAPI {
+metricsPurge(uint32_t a_timestamp, LogContext)
#dbGet(const char *a_url_path, const std::vector<std::pair<std::string, std::string>> &a_params, libjson::Value &a_result, LogContext, bool a_log = true)
#dbPost(const char *a_url_path, const std::vector<std::pair<std::string, std::string>> &a_params, const std::string *a_body, libjson::Value &a_result, LogContext)
-setAuthStatus(Anon::AuthStatusReply &a_reply, const libjson::Value &a_result)
-setUserData(Auth::UserDataReply &a_reply, const libjson::Value &a_result)
}
class TestDatabaseAPI {
+TestDatabaseAPI(const std::string &a_db_url, const std::string &a_db_user, const std::string &a_db_pass)
+~TestDatabaseAPI()
+dbGet(const char *a_url_path, const std::vector<std::pair<std::string, std::string>> &a_params, libjson::Value &a_result, LogContext, bool a_log = true)
+dbGetRaw(const char *a_url_path, const std::vector<std::pair<std::string, std::string>> &a_params, std::string &a_result)
+dbPost(const char *a_url_path, const std::vector<std::pair<std::string, std::string>> &a_params, const std::string *a_body, libjson::Value &a_result, LogContext)
}
TestDatabaseAPI --> DatabaseAPI
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @nedvedba - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider using inheritance instead of duplicating the database access methods. TestDatabaseAPI should extend DatabaseAPI if you need to override behavior for testing.
- Rather than modifying access levels and duplicating code, consider using dependency injection and a mocking framework for testing. This would maintain better encapsulation and reduce code duplication.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
core/server/TestDatabaseAPI.hpp
Outdated
namespace SDMS { | ||
namespace Core { | ||
|
||
class TestDatabaseAPI { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider having TestDatabaseAPI inherit from DatabaseAPI to avoid code duplication
The database access methods are currently duplicated between DatabaseAPI and TestDatabaseAPI. Since these methods are now protected in DatabaseAPI, you could inherit from it and override only the methods that need different behavior for testing.
class TestDatabaseAPI : public DatabaseAPI {
dce6aad
to
130807f
Compare
130807f
to
e9bb510
Compare
@par-hermes format |
Just get unit test working . |
Summary by Sourcery
Introduce a TestDatabaseAPI class to facilitate testing of database interactions and modify access specifiers in DatabaseAPI to support subclassing.
New Features:
Enhancements: