]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/common/test_context.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / common / test_context.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
7 *
8 * Author: Loic Dachary <loic@dachary.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library Public License for more details.
19 *
20 *
21 */
22#include "gtest/gtest.h"
23#include "include/types.h"
24#include "include/msgr.h"
25#include "common/ceph_context.h"
26#include "common/config.h"
27#include "log/Log.h"
28
29TEST(CephContext, do_command)
30{
31 CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get();
32
33 cct->_conf->cluster = "ceph";
34
35 string key("key");
36 string value("value");
37 cct->_conf->set_val(key.c_str(), value.c_str(), false);
38 cmdmap_t cmdmap;
39 cmdmap["var"] = key;
40
41 {
42 bufferlist out;
43 cct->do_command("config get", cmdmap, "xml", &out);
44 string s(out.c_str(), out.length());
45 EXPECT_EQ("<config_get><key>" + value + "</key></config_get>", s);
46 }
47
48 {
49 bufferlist out;
50 cct->do_command("config get", cmdmap, "UNSUPPORTED", &out);
51 string s(out.c_str(), out.length());
52 EXPECT_EQ("{\n \"key\": \"value\"\n}\n", s);
53 }
54
55 cct->put();
56}
57
58TEST(CephContext, experimental_features)
59{
60 CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get();
61
62 cct->_conf->cluster = "ceph";
63
64 ASSERT_FALSE(cct->check_experimental_feature_enabled("foo"));
65 ASSERT_FALSE(cct->check_experimental_feature_enabled("bar"));
66 ASSERT_FALSE(cct->check_experimental_feature_enabled("baz"));
67
68 cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features",
69 "foo,bar");
70 cct->_conf->apply_changes(&cout);
71 ASSERT_TRUE(cct->check_experimental_feature_enabled("foo"));
72 ASSERT_TRUE(cct->check_experimental_feature_enabled("bar"));
73 ASSERT_FALSE(cct->check_experimental_feature_enabled("baz"));
74
75 cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features",
76 "foo bar");
77 cct->_conf->apply_changes(&cout);
78 ASSERT_TRUE(cct->check_experimental_feature_enabled("foo"));
79 ASSERT_TRUE(cct->check_experimental_feature_enabled("bar"));
80 ASSERT_FALSE(cct->check_experimental_feature_enabled("baz"));
81
82 cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features",
83 "baz foo");
84 cct->_conf->apply_changes(&cout);
85 ASSERT_TRUE(cct->check_experimental_feature_enabled("foo"));
86 ASSERT_FALSE(cct->check_experimental_feature_enabled("bar"));
87 ASSERT_TRUE(cct->check_experimental_feature_enabled("baz"));
88
89 cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features",
90 "*");
91 cct->_conf->apply_changes(&cout);
92 ASSERT_TRUE(cct->check_experimental_feature_enabled("foo"));
93 ASSERT_TRUE(cct->check_experimental_feature_enabled("bar"));
94 ASSERT_TRUE(cct->check_experimental_feature_enabled("baz"));
95
96 cct->_log->flush();
97}
98
99/*
100 * Local Variables:
101 * compile-command: "cd ../.. ;
102 * make unittest_context &&
103 * valgrind \
104 * --max-stackframe=20000000 --tool=memcheck \
105 * ./unittest_context # --gtest_filter=CephContext.*
106 * "
107 * End:
108 */