Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(log-analyzer-cli main.cpp)
add_executable(log-analyzer-cli main.cpp reporter.cpp)
target_link_libraries(log-analyzer-cli core_lib)

set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY EP_PREFIX ${CMAKE_BINARY_DIR})
5 changes: 4 additions & 1 deletion cli/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../core/analyzer.h"
#include "reporter.h"
#include <iostream>

int main() {
Expand All @@ -7,7 +8,9 @@ int main() {
std::getline(std::cin, path);

Analyzer analysis;
std::string report = analysis.analyze(path);
AnalysisResult result = analysis.analyze(path);
Reporter reporter;
std::string report = reporter.GenerateTextReport(result);

std::cout << report;

Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion core/reporter.h → cli/reporter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "common.h"

#include "../core/common.h"

#include <vector>

Expand Down
1 change: 0 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ add_library(core_lib
reader.cpp
parser.cpp
statistics.cpp
reporter.cpp
analyzer.cpp
)
5 changes: 2 additions & 3 deletions core/analyzer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "analyzer.h"

std::string Analyzer::analyze(std::string path) {
AnalysisResult Analyzer::analyze(std::string path) {
reader_.OpenFile(path);

AnalysisResult res;
Expand All @@ -11,7 +11,6 @@ std::string Analyzer::analyze(std::string path) {
}

reader_.CloseFile();
std::string report = reporter_.GenerateTextReport(res);

return report;
return res;
}
4 changes: 1 addition & 3 deletions core/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
#include "reader.h"
#include "parser.h"
#include "statistics.h"
#include "reporter.h"
#include <string>

class Analyzer {
private:
Reader reader_;
Parser parser_;
Reporter reporter_;
Statistics statistics_;

public:
std::string analyze(std::string path);
AnalysisResult analyze(std::string path);
};

1 change: 0 additions & 1 deletion core/parser.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "parser.h"
#include <iostream>

LogFormat Parser::DetectFormat(const std::string& line) {
if (line.find("HTTP/1.0") != std::string::npos) {
Expand Down
1 change: 0 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_executable(test-runner
test_reader.cpp
test_parser.cpp
test_statistics.cpp
test_reporter.cpp
test_analyzer.cpp
)

Expand Down
18 changes: 9 additions & 9 deletions tests/test_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
TEST(AnalyzerTest, StandardTest) {
Analyzer analyzer;
fs::path path = fs::path("test_data") / "normal_test.log";
std::string report = analyzer.analyze(path.string());
AnalysisResult res = analyzer.analyze(path.string());

EXPECT_TRUE(report.find("Sucсessful - 5") != std::string::npos);
EXPECT_TRUE(report.find("Failed Parsing - 8") != std::string::npos);
EXPECT_TRUE(report.find("192.168.2.145 - 4") != std::string::npos);
EXPECT_TRUE(report.find("20:00 - 2") != std::string::npos);
EXPECT_TRUE(report.find("500 - 2") != std::string::npos);
EXPECT_FALSE(report.find("402 - 1") != std::string::npos);
EXPECT_TRUE(res.successful_requests == 5);
EXPECT_TRUE(res.failed_parses == 8);
EXPECT_TRUE(res.ip["192.168.2.145"] == 4);
EXPECT_TRUE(res.time_distribution["20:00"] == 2);
EXPECT_TRUE(res.error_counts["500"] == 2);
EXPECT_FALSE(res.error_counts["402"] == 2);
}

TEST(AnalyzerTest, EmptyTest) {
Analyzer analyzer;
fs::path path = fs::path("test_data") / "empty_test.log";
std::string report = analyzer.analyze(path.string());
AnalysisResult res = analyzer.analyze(path.string());

EXPECT_TRUE(report == "invalid file format or file empty");
EXPECT_TRUE(res.total_processed == 0);
}
53 changes: 0 additions & 53 deletions tests/test_reporter.cpp

This file was deleted.

1 change: 0 additions & 1 deletion tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "../core/reader.h"
#include "../core/parser.h"
#include "../core/statistics.h"
#include "../core/reporter.h"
#include "../core/analyzer.h"

#include <filesystem>
Expand Down