Skip to content
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 globus api #1049

Open
wants to merge 3 commits into
base: 1044-bug-fix
Choose a base branch
from

Conversation

nedvedba
Copy link
Collaborator

@nedvedba nedvedba commented Nov 7, 2024

Summary by Sourcery

Add a test class TestGlobusAPI to enable testing of the GlobusAPI class by exposing its get and post methods. Modify the init method's access level in GlobusAPI to protected to support subclassing.

Enhancements:

  • Change the access modifier of the init method in GlobusAPI from private to protected to allow subclassing.

Tests:

  • Introduce a new test class TestGlobusAPI to facilitate testing of the GlobusAPI class by providing public access to its get and post methods.

@nedvedba nedvedba added the Type: Bug Something isn't working label Nov 7, 2024
@nedvedba nedvedba self-assigned this Nov 7, 2024
Copy link

sourcery-ai bot commented Nov 7, 2024

Reviewer's Guide by Sourcery

The changes introduce a new test class TestGlobusAPI that inherits from GlobusAPI to facilitate unit testing. The implementation modifies access specifiers in GlobusAPI to make certain methods accessible to the test class and sets up the basic test infrastructure with Boost Test framework.

Class diagram for GlobusAPI and TestGlobusAPI

classDiagram
    class GlobusAPI {
        -void init()
        protected long get(CURL *a_curl, const std::string &a_base_url, const std::string &a_url_path, const std::string &a_token, const std::vector<std::pair<std::string, std::string>> &a_params, std::string &a_result)
        protected long post(CURL *a_curl, const std::string &a_base_url, const std::string &a_url_path, const std::string &a_token, const std::vector<std::pair<std::string, std::string>> &a_params, const libjson::Value *a_body, std::string &a_result)
        private std::string getSubmissionID(const std::string &a_acc_token)
        private bool eventsHaveErrors(const std::vector<std::string> &a_events, XfrStatus &status, std::string &a_err_msg)
    }
    class TestGlobusAPI {
        +TestGlobusAPI()
        +~TestGlobusAPI()
        +long get(CURL *a_curl, const std::string &a_base_url, const std::string &a_url_path, const std::string &a_token, const std::vector<std::pair<std::string, std::string>> &a_params, std::string &a_result)
        +long post(CURL *a_curl, const std::string &a_base_url, const std::string &a_url_path, const std::string &a_token, const std::vector<std::pair<std::string, std::string>> &a_params, const libjson::Value *a_body, std::string &a_result)
    }
    GlobusAPI <|-- TestGlobusAPI
    note for GlobusAPI "The init method access specifier changed from private to protected."
Loading

File-Level Changes

Change Details Files
Created a new test class that inherits from GlobusAPI
  • Defined TestGlobusAPI class with inheritance from GlobusAPI
  • Added constructor that calls GlobusAPI::init()
  • Created wrapper methods for get() and post() that call parent class implementations
core/server/tests/unit/test_GlobusAPI.cpp
Modified access specifiers in GlobusAPI class
  • Moved get() and post() methods from private to protected section
  • Kept init() method in private section
core/server/GlobusAPI.hpp
Set up test cases infrastructure
  • Added necessary include statements for testing
  • Created test cases for GlobusAPI get and post operations
  • Added Config instance initialization in test cases
core/server/tests/unit/test_GlobusAPI.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a 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:

  • The constructor and destructor should be declared in the public section of the class
  • Missing public inheritance specifier - should be class TestGlobusAPI : public GlobusAPI
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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

namespace SDMS {
namespace Core {

class TestGlobusAPI: GlobusAPI {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Missing public inheritance specifier and constructor/destructor should be public

The class should use 'public' inheritance (': public GlobusAPI'), and the constructor/destructor should be moved under a public access specifier to allow instantiation of the test class.

@nedvedba nedvedba changed the base branch from release_June_2024 to 1066-bug-fix November 11, 2024 10:25
@nedvedba nedvedba changed the base branch from 1066-bug-fix to 1044-bug-fix November 11, 2024 10:29
@JoshuaSBrown
Copy link
Collaborator

Just fix unit test issue, and run par herems formatter.

@JoshuaSBrown
Copy link
Collaborator

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a 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:

  • There's a syntax error in TestGlobusAPI constructor - missing semicolon after GlobusAPI::init()
  • TestGlobusAPI api() declares a function instead of creating an object - remove the parentheses to fix the most vexing parse
  • Consider making init() protected instead of private since derived test class needs to call it
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +27 to +36
class TestGlobusAPI: public GlobusAPI {
public:
TestGlobusAPI() {
GlobusAPI::init()
}

~TestGlobusAPI() {}

long get(CURL *a_curl, const std::string &a_base_url,
const std::string &a_url_path, const std::string &a_token,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test class could benefit from mock methods for better testing isolation

Consider adding mock methods to override the actual HTTP calls in the test class. This would allow testing the API without making real network requests and enable testing of error scenarios. You could use dependency injection for the CURL handle to facilitate this.

class TestGlobusAPI: public GlobusAPI {
public:
  TestGlobusAPI(): mock_response_code_(200) {}
  ~TestGlobusAPI() = default;

  void set_mock_response(long code, const std::string& response) {
    mock_response_code_ = code;
    mock_response_ = response;
  }

  long get(CURL*, const std::string&, const std::string&, const std::string&,
          const std::vector<std::pair<std::string, std::string>>&, std::string& result) override {
    result = mock_response_;
    return mock_response_code_;
  }

  long post(CURL*, const std::string&, const std::string&, const std::string&,
           const std::vector<std::pair<std::string, std::string>>&, 
           const libjson::Value*, std::string& result) override {
    result = mock_response_;
    return mock_response_code_;
  }

private:
  long mock_response_code_;
  std::string mock_response_;
};

Comment on lines +29 to +30
TestGlobusAPI() {
GlobusAPI::init()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Missing semicolon after init() call and no error handling in constructor

The init() call is missing a semicolon. Additionally, consider adding error handling and a test case that verifies proper initialization and handling of initialization failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants