Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
namchuai committed Sep 13, 2024
1 parent 457e5a3 commit c6a0e28
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions engine/commands/engine_init_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ bool EngineInitCmd::Exec() const {
std::string engine_path =
file_manager_utils::GetCortexDataPath().string() +
get_engine_path(engineName_);
archive_utils::ExtractArchive(finishedTask.items[0].localPath,
engine_path);
archive_utils::ExtractArchive(
finishedTask.items[0].localPath.string(), engine_path);

try {
std::filesystem::remove(finishedTask.items[0].localPath);
Expand Down
26 changes: 26 additions & 0 deletions engine/test/components/test_url_parser.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "gtest/gtest.h"
#include "utils/url_parser.h"

class UrlParserTestSuite : public ::testing::Test {
protected:
constexpr static auto kValidUrlWithOnlyPaths{"https://jan.ai/path1/path2"};
};

TEST_F(UrlParserTestSuite, TestParseUrlCorrectly) {
auto url = url_parser::FromUrlString(kValidUrlWithOnlyPaths);

EXPECT_EQ(url.host, "jan.ai");
EXPECT_EQ(url.protocol, "https");
EXPECT_EQ(url.pathParams.size(), 2);
}

TEST_F(UrlParserTestSuite, ConstructUrlCorrectly) {
auto url = url_parser::Url{
.protocol = "https",
.host = "jan.ai",
.pathParams = {"path1", "path2"},
};
auto url_str = url_parser::FromUrl(url);

EXPECT_EQ(url_str, kValidUrlWithOnlyPaths);
}
4 changes: 4 additions & 0 deletions engine/utils/url_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <sstream>
#include <string>
#include <unordered_map>
#include <variant>
#include <vector>
#include "exceptions/malformed_url_exception.h"

Expand All @@ -26,6 +27,9 @@ inline void SplitPathParams(const std::string& input,
std::string token;
std::istringstream tokenStream(input);
while (std::getline(tokenStream, token, '/')) {
if (token.empty()) {
continue;
}
pathList.push_back(token);
}
}
Expand Down

0 comments on commit c6a0e28

Please sign in to comment.