aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/metrics/fake_ut.cpp
blob: c3368ca302102b9742304adc16fe91a520bf5162 (plain) (blame)
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
#include "fake.h"

#include <library/cpp/testing/unittest/registar.h>

#include <util/generic/ptr.h>

using namespace NMonitoring;

Y_UNIT_TEST_SUITE(TFakeTest) {

    Y_UNIT_TEST(CreateOnStack) {
        TFakeMetricRegistry registry;
    }

    Y_UNIT_TEST(CreateOnHeap) {
        auto registry = MakeAtomicShared<TFakeMetricRegistry>();
        UNIT_ASSERT(registry);
    }

    Y_UNIT_TEST(Gauge) {
        TFakeMetricRegistry registry(TLabels{{"common", "label"}});

        IGauge* g = registry.Gauge(MakeLabels({{"my", "gauge"}}));
        UNIT_ASSERT(g);

        UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 0.0, 1E-6);
        g->Set(12.34);
        UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 0.0, 1E-6); // no changes

        double val = g->Add(1.2);
        UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 0.0, 1E-6);
        UNIT_ASSERT_DOUBLES_EQUAL(val, 0.0, 1E-6);
    }
}