summaryrefslogtreecommitdiffstats
path: root/src/test/admin_socket_output_tests.cc
blob: 58bc036540805a8a79d6335979cc88d451334279 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2017 Red Hat
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */

#include <string>
#include <iostream>

#include "common/ceph_json.h"

// Test functions

// Example test function
/*
bool test_config_get_admin_socket(std::string& output) {
  return std::string::npos != output.find("admin_socket") &&
         std::string::npos != output.rfind(".asok");
}
*/

bool test_dump_pgstate_history(std::string &output) {
  JSONParser parser;
  bool ret = parser.parse(output.c_str(), output.size());
  if (!ret) {
    std::cerr << "test_dump_pgstate_history: parse error" << std::endl;
    return false;
  }

  JSONObjIter iter = parser.find_first();
  if (iter.end()) { //Empty
    std::cerr << "test_dump_pgstate_history: command output empty, failing"
              << std::endl;
    return false;
  }
  for (; !iter.end(); ++iter) {
    if ((*iter)->get_name() == "pg") {
      ret = !(*iter)->get_data().empty();
      if (ret == false) {
        std::cerr << "test_dump_pgstate_history: pg value empty, failing"
                  << std::endl;
        std::cerr << "Dumping full output: " << std::endl;
        std::cerr << output << std::endl;
        break;
      }
    } else if ((*iter)->get_name() == "history") {
      ret = std::string::npos != (*iter)->get_data().find("epoch") &&
            std::string::npos != (*iter)->get_data().find("state") &&
            std::string::npos != (*iter)->get_data().find("Initial") &&
            std::string::npos != (*iter)->get_data().find("enter") &&
            std::string::npos != (*iter)->get_data().find("exit");
      if (ret == false) {
        std::cerr << "test_dump_pgstate_history: Can't find expected values in "
                     "history object, failing"
                  << std::endl;
        std::cerr << "Problem output was:" << std::endl;
        std::cerr << (*iter)->get_data() << std::endl;
        break;
      }
    }
  }
  return ret;
}