Skip to content

Commit

Permalink
mv apis stat into App
Browse files Browse the repository at this point in the history
  • Loading branch information
sumory committed Dec 24, 2017
1 parent e17c4e0 commit eb97ef1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project (ciao C CXX)
# some configuration.
set (CIAO_VERSION_MAJOR 0)
set (CIAO_VERSION_MINOR 0)
set (CIAO_VERSION_PATCH 1)
set (CIAO_VERSION_PATCH 4)
option (INJECT_BUILD_DATE "inject build date or not" ON)

configure_file (
Expand Down
31 changes: 0 additions & 31 deletions ciao/api_stat.h

This file was deleted.

17 changes: 17 additions & 0 deletions ciao/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,23 @@ class App {
return *this;
}
// basic methods end.

// stat
std::vector<std::pair<std::string, std::string>> stat() {
std::vector<std::pair<std::string, std::string>> result;
router->trie.walk_trie(result);
return result;
}

std::string text_stat() {
std::vector<std::pair<std::string, std::string>> result = stat();
std::string content;
for (auto& r : result) {
content += r.first + "\t" + r.second;
content += "\n";
}
return content;
}
};

} // namespace ciao
2 changes: 1 addition & 1 deletion ciao/config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#define CIAO_VERSION_MAJOR 0
#define CIAO_VERSION_MINOR 0
#define CIAO_VERSION_PATCH 1
#define CIAO_VERSION_PATCH 4
#define INJECT_BUILD_DATE
10 changes: 4 additions & 6 deletions test/utils/api_stat_test.cc → test/app/api_stat_test.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "ciao/api_stat.h"
#include "ciao/utils.h"
#include "ciao/app.h"
#include "test/test_common.h"

TEST_F(UtilsTest, ApiStatTest) {
TEST_F(AppTest, ApiStatTest) {
ciao::App app;
auto mw = [](ciao::Request& req, ciao::Response& res, ciao::Next& next) {};
app.get("/get", mw);
Expand All @@ -24,8 +23,7 @@ TEST_F(UtilsTest, ApiStatTest) {
app.get("/article/view", mw);
app.post("/article/modify", mw);

ciao::ApiStat api_stat(&app);
auto stat = api_stat.stat();
auto stat = app.stat();
ASSERT_EQ(15lu, stat.size());
std::cout << api_stat.text_stat() << std::endl;
// std::cout << app.text_stat() << std::endl;
}

0 comments on commit eb97ef1

Please sign in to comment.