|
| 1 | +/** @file |
| 2 | +
|
| 3 | + Catch-based tests for RecDumpRecords |
| 4 | +
|
| 5 | + @section license License |
| 6 | +
|
| 7 | + Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. |
| 8 | + See the NOTICE file distributed with this work for additional information regarding copyright |
| 9 | + ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 10 | + "License"); you may not use this file except in compliance with the License. You may obtain a |
| 11 | + copy of the License at |
| 12 | +
|
| 13 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +
|
| 15 | + Unless required by applicable law or agreed to in writing, software distributed under the License |
| 16 | + is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 17 | + or implied. See the License for the specific language governing permissions and limitations under |
| 18 | + the License. |
| 19 | + */ |
| 20 | +#include <catch2/catch_test_macros.hpp> |
| 21 | +#include <string> |
| 22 | +#include <vector> |
| 23 | + |
| 24 | +#include "../P_RecCore.h" |
| 25 | +#include "tsutil/Metrics.h" |
| 26 | + |
| 27 | +struct DumpEntry { |
| 28 | + RecT rec_type; |
| 29 | + int registered; |
| 30 | + std::string name; |
| 31 | + int data_type; |
| 32 | + std::string string_value; |
| 33 | + RecInt int_value{0}; |
| 34 | +}; |
| 35 | + |
| 36 | +static void |
| 37 | +collect_callback(RecT rec_type, void *edata, int registered, const char *name, int data_type, RecData *datum) |
| 38 | +{ |
| 39 | + auto *entries = static_cast<std::vector<DumpEntry> *>(edata); |
| 40 | + DumpEntry entry; |
| 41 | + |
| 42 | + entry.rec_type = rec_type; |
| 43 | + entry.registered = registered; |
| 44 | + entry.name = name; |
| 45 | + entry.data_type = data_type; |
| 46 | + |
| 47 | + if (data_type == RECD_STRING && datum->rec_string != nullptr) { |
| 48 | + entry.string_value = datum->rec_string; |
| 49 | + } else if (data_type == RECD_INT || data_type == RECD_COUNTER) { |
| 50 | + entry.int_value = datum->rec_int; |
| 51 | + } |
| 52 | + |
| 53 | + entries->push_back(std::move(entry)); |
| 54 | +} |
| 55 | + |
| 56 | +TEST_CASE("RecDumpRecords - StaticString metrics", "[librecords][RecDump]") |
| 57 | +{ |
| 58 | + const std::string test_name = "proxy.test.dump.string_metric"; |
| 59 | + const std::string test_value = "test_string_value"; |
| 60 | + |
| 61 | + ts::Metrics::StaticString::createString(test_name, test_value); |
| 62 | + |
| 63 | + std::vector<DumpEntry> entries; |
| 64 | + |
| 65 | + RecDumpRecords(RECT_NULL, collect_callback, &entries); |
| 66 | + |
| 67 | + bool found = false; |
| 68 | + |
| 69 | + for (const auto &entry : entries) { |
| 70 | + if (entry.name == test_name) { |
| 71 | + found = true; |
| 72 | + CHECK(entry.rec_type == RECT_PLUGIN); |
| 73 | + CHECK(entry.registered == 1); |
| 74 | + CHECK(entry.data_type == RECD_STRING); |
| 75 | + CHECK(entry.string_value == test_value); |
| 76 | + break; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + REQUIRE(found); |
| 81 | +} |
0 commit comments