aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/common/state_reporter_utils/state_reporter_utils_test.cpp
blob: 749f8b147ac6d69a5c4e259a02e4d8192de0d84f (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
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/log/log.h>
LOG_SETUP("state_reporter_utils_test");

#include <vespa/searchcore/proton/common/state_reporter_utils.h>
#include <vespa/vespalib/data/slime/slime.h>
#include <vespa/vespalib/testkit/testapp.h>

using namespace proton;
using namespace vespalib::slime;
using vespalib::Slime;

vespalib::string
toString(const StatusReport &statusReport)
{
    Slime slime;
    StateReporterUtils::convertToSlime(statusReport, SlimeInserter(slime));
    return slime.toString();
}

TEST("require that simple status report is correctly converted to slime")
{
    EXPECT_EQUAL(
            "{\n"
            "    \"state\": \"ONLINE\"\n"
            "}\n",
            toString(StatusReport(StatusReport::Params("").
                    internalState("ONLINE"))));
}

TEST("require that advanced status report is correctly converted to slime")
{
    EXPECT_EQUAL(
            "{\n"
            "    \"state\": \"REPLAY\",\n"
            "    \"progress\": 65.5,\n"
            "    \"configState\": \"OK\",\n"
            "    \"message\": \"foo\"\n"
            "}\n",
            toString(StatusReport(StatusReport::Params("").
                    internalState("REPLAY").
                    progress(65.5).
                    internalConfigState("OK").
                    message("foo"))));
}

TEST_MAIN() { TEST_RUN_ALL(); }