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 initial test case for globus api #1050

Open
wants to merge 7 commits into
base: 1066-bug-fix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions core/server/GlobusAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ class GlobusAPI {
void refreshAccessToken(const std::string &a_ref_tok,
std::string &a_new_acc_tok, uint32_t &a_expires_in);

private:
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,
Expand All @@ -77,12 +76,15 @@ class GlobusAPI {
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);

Config &m_config;

private:
void init();
std::string getSubmissionID(const std::string &a_acc_token);
bool eventsHaveErrors(const std::vector<std::string> &a_events,
XfrStatus &status, std::string &a_err_msg);
void checkResponsCode(long a_code, libjson::Value::Object &a_body) const;

Config &m_config;
CURL *m_curl_xfr;
CURL *m_curl_auth;
LogContext m_log_context;
Expand Down
1 change: 1 addition & 0 deletions core/server/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
foreach(PROG
test_AuthMap
test_AuthenticationManager
test_GlobusAPI
)

file(GLOB ${PROG}_SOURCES ${PROG}*.cpp)
Expand Down
93 changes: 93 additions & 0 deletions core/server/tests/unit/test_GlobusAPI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#define BOOST_TEST_MAIN

#define BOOST_TEST_MODULE globusapi

// Local private includes
#include "GlobusAPI.hpp"
// #include "Config.hpp"

// Local public includes
#include "common/DynaLog.hpp"
#include "common/libjson.hpp"
#include "common/Util.hpp"

// Third party includes
#include <curl/curl.h>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>

// Standard includes
#include <string>
#include <vector>
#include <map>
#include <memory>

using namespace libjson;
using namespace SDMS::Core;

class TestGlobusAPI: public GlobusAPI {
public:
TestGlobusAPI() {}

~TestGlobusAPI() {}

void setupConfig() {

}

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) {
return GlobusAPI::get(a_curl, a_base_url, a_url_path, a_token, a_params, 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) {
return GlobusAPI::post(a_curl, a_base_url, a_url_path, a_token, a_params, a_body, a_result);
}
};

CURL* curl_setup() {
CURL* m_curl = curl_easy_init();
if (!m_curl)
EXCEPT(1, "libcurl init failed");

curl_easy_setopt(m_curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, curlResponseWriteCB);
curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(m_curl, CURLOPT_TCP_NODELAY, 1);
}

BOOST_AUTO_TEST_SUITE(GlobusAPITest)

BOOST_AUTO_TEST_CASE(testing_GlobusAPIPost) {
TestGlobusAPI api;
api.setupConfig();
CURL* m_curl = curl_setup();
Value body;
Value::Object &body_o = body.initObject();
body_o["username"] = "admin";
body_o["password"] = "password123";
std::string res;

api.post(m_curl, "https://restful-booker.herokuapp.com/", "auth", "", {{"field","test"}}, &body, res);

BOOST_TEST(true);
Copy link

Choose a reason for hiding this comment

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

issue (testing): Empty test case for GlobusAPIGet

This test case is currently just asserting true, which doesn't validate any actual functionality. Consider adding meaningful assertions that verify the GET request behavior, including successful responses, error handling, and edge cases like invalid endpoints or authentication failures.

}

BOOST_AUTO_TEST_CASE(testing_GlobusAPIGet) {
TestGlobusAPI api;
api.setupConfig();
CURL* m_curl = curl_setup();
std::string res;

api.get(m_curl, "https://restful-booker.herokuapp.com/", "booking", "authtoken", {{"field","test"}}, res);

BOOST_TEST(true);
}

BOOST_AUTO_TEST_SUITE_END()
Loading