forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_admin_test.h
64 lines (51 loc) · 2.27 KB
/
integration_admin_test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include "common/json/json_loader.h"
#include "test/integration/http_integration.h"
#include "gtest/gtest.h"
namespace Envoy {
class IntegrationAdminTest : public HttpIntegrationTest,
public testing::TestWithParam<Network::Address::IpVersion> {
public:
IntegrationAdminTest()
: HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {}
void initialize() override {
config_helper_.addFilter(ConfigHelper::DEFAULT_HEALTH_CHECK_FILTER);
HttpIntegrationTest::initialize();
}
/**
* Destructor for an individual test.
*/
void TearDown() override {
test_server_.reset();
fake_upstreams_.clear();
}
/**
* Validates that the passed in string conforms to output of stats in JSON format.
*/
void validateStatsJson(const std::string stats_json, const uint64_t expected_hist_count) {
Json::ObjectSharedPtr statsjson = Json::Factory::loadFromString(stats_json);
EXPECT_TRUE(statsjson->hasObject("stats"));
uint64_t histogram_count = 0;
for (Json::ObjectSharedPtr obj_ptr : statsjson->getObjectArray("stats")) {
if (obj_ptr->hasObject("histograms")) {
histogram_count++;
const Json::ObjectSharedPtr& histograms_ptr = obj_ptr->getObject("histograms");
// Validate that both supported_quantiles and computed_quantiles are present in JSON.
EXPECT_TRUE(histograms_ptr->hasObject("supported_quantiles"));
EXPECT_TRUE(histograms_ptr->hasObject("computed_quantiles"));
const std::vector<Json::ObjectSharedPtr>& computed_quantiles =
histograms_ptr->getObjectArray("computed_quantiles");
EXPECT_GT(computed_quantiles.size(), 0);
// Validate that each computed_quantile has name and value objects.
EXPECT_TRUE(computed_quantiles[0]->hasObject("name"));
EXPECT_TRUE(computed_quantiles[0]->hasObject("values"));
// Validate that supported and computed quantiles are of the same size.
EXPECT_EQ(histograms_ptr->getObjectArray("supported_quantiles").size(),
computed_quantiles[0]->getObjectArray("values").size());
}
}
// Validate that the stats JSON has expected histograms element.
EXPECT_EQ(expected_hist_count, histogram_count);
}
};
} // namespace Envoy