Skip to content

Commit

Permalink
Merge pull request #336 from jupp0r/exposer-listening-ports
Browse files Browse the repository at this point in the history
feat(pull): Add getter for listening ports
  • Loading branch information
gjasny committed Feb 14, 2020
2 parents fbf3244 + 3018a51 commit c81eca3
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/tests/CMakeLists.txt
@@ -1,5 +1,5 @@

add_executable(prometheus_test
add_executable(prometheus_core_test
builder_test.cc
check_names_test.cc
counter_test.cc
Expand All @@ -13,13 +13,13 @@ add_executable(prometheus_test
utils_test.cc
)

target_link_libraries(prometheus_test
target_link_libraries(prometheus_core_test
PRIVATE
${PROJECT_NAME}::core
GTest::gmock_main
)

add_test(
NAME prometheus_test
COMMAND prometheus_test
NAME prometheus_core_test
COMMAND prometheus_core_test
)
2 changes: 2 additions & 0 deletions pull/include/prometheus/exposer.h
Expand Up @@ -26,6 +26,8 @@ class PROMETHEUS_CPP_PULL_EXPORT Exposer {
~Exposer();
void RegisterCollectable(const std::weak_ptr<Collectable>& collectable);

std::vector<int> GetListeningPorts() const;

private:
std::unique_ptr<CivetServer> server_;
std::vector<std::weak_ptr<Collectable>> collectables_;
Expand Down
5 changes: 5 additions & 0 deletions pull/src/exposer.cc
Expand Up @@ -30,4 +30,9 @@ void Exposer::RegisterCollectable(
const std::weak_ptr<Collectable>& collectable) {
collectables_.push_back(collectable);
}

std::vector<int> Exposer::GetListeningPorts() const {
return server_->getListeningPorts();
}

} // namespace prometheus
1 change: 1 addition & 0 deletions pull/tests/CMakeLists.txt
@@ -1 +1,2 @@
add_subdirectory(integration)
add_subdirectory(unit)
13 changes: 13 additions & 0 deletions pull/tests/unit/BUILD.bazel
@@ -0,0 +1,13 @@
cc_test(
name = "unit",
srcs = glob([
"*.cc",
"*.h",
]),
copts = ["-Iexternal/googletest/include"],
linkstatic = True,
deps = [
"//pull",
"@com_google_googletest//:gtest_main",
],
)
15 changes: 15 additions & 0 deletions pull/tests/unit/CMakeLists.txt
@@ -0,0 +1,15 @@

add_executable(prometheus_pull_test
exposer_test.cc
)

target_link_libraries(prometheus_pull_test
PRIVATE
${PROJECT_NAME}::pull
GTest::gmock_main
)

add_test(
NAME prometheus_pull_test
COMMAND prometheus_pull_test
)
25 changes: 25 additions & 0 deletions pull/tests/unit/exposer_test.cc
@@ -0,0 +1,25 @@
#include "prometheus/exposer.h"

#include <gmock/gmock.h>

namespace prometheus {
namespace {

using namespace testing;

TEST(ExposerTest, listenOnDistinctPorts) {
Exposer firstExposer{"0.0.0.0:0"};
auto firstExposerPorts = firstExposer.GetListeningPorts();
ASSERT_EQ(1u, firstExposerPorts.size());
EXPECT_NE(0, firstExposerPorts.front());

Exposer secondExposer{"0.0.0.0:0"};
auto secondExposerPorts = secondExposer.GetListeningPorts();
ASSERT_EQ(1u, secondExposerPorts.size());
EXPECT_NE(0, secondExposerPorts.front());

EXPECT_NE(firstExposerPorts, secondExposerPorts);
}

} // namespace
} // namespace prometheus

0 comments on commit c81eca3

Please sign in to comment.