aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/common/hostreporter/util.cpp
blob: e0563a431e6d2eb8a47244bf13024d5c54e1d53e (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "util.h"
#include <vespa/storage/common/hostreporter/hostreporter.h>
#include <vespa/vespalib/data/slime/slime.h>
#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/vespalib/util/jsonstream.h>
#include <vespa/vespalib/stllike/asciistream.h>

namespace storage {
namespace util {
namespace {
using Object = vespalib::JsonStream::Object;
using End = vespalib::JsonStream::End;
using JsonFormat = vespalib::slime::JsonFormat;
using Memory = vespalib::Memory;
}

void
reporterToSlime(HostReporter &hostReporter, vespalib::Slime &slime) {
    vespalib::asciistream json;
    vespalib::JsonStream stream(json, true);

    stream << Object();
    hostReporter.report(stream);
    stream << End();
    std::string jsonData = json.str();
    size_t parsed = JsonFormat::decode(Memory(jsonData), slime);

    if (parsed == 0) {
        CPPUNIT_FAIL("jsonData is not json:\n" + jsonData);
    }
}
}
}