blob: e4378f22ccf4a3dead0aa7e7025a38e2deb23924 (
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
48
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "util.h"
#include <vespa/storage/common/hostreporter/hostinfo.h>
#include <vespa/storage/common/hostreporter/hostreporter.h>
#include <vespa/vespalib/data/slime/slime.h>
#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/util/jsonstream.h>
#include <vespa/vespalib/gtest/gtest.h>
using namespace ::testing;
namespace storage {
namespace {
using Object = vespalib::JsonStream::Object;
using End = vespalib::JsonStream::End;
using JsonFormat = vespalib::slime::JsonFormat;
using Memory = vespalib::Memory;
class DummyReporter: public HostReporter {
public:
void report(vespalib::JsonStream& jsonreport) override {
jsonreport << "dummy" << Object() << "foo" << "bar" << End();
}
};
}
TEST(HostInfoReporterTest, host_info_reporter) {
HostInfo hostinfo;
DummyReporter dummyReporter;
hostinfo.registerReporter(&dummyReporter);
vespalib::asciistream json;
vespalib::JsonStream stream(json, true);
stream << Object();
hostinfo.printReport(stream);
stream << End();
std::string jsonData = json.str();
vespalib::Slime slime;
JsonFormat::decode(Memory(jsonData), slime);
EXPECT_EQ(slime.get()["dummy"]["foo"].asString(), "bar");
EXPECT_FALSE(slime.get()["vtag"]["version"].asString().make_string().empty());
}
} // storage
|