1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
8 * Author: Loic Dachary <loic@dachary.org>
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)
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.
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"
29 TEST(CephContext, do_command)
31 CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get();
33 cct->_conf->cluster = "ceph";
36 string value("value");
37 cct->_conf->set_val(key.c_str(), value.c_str(), false);
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);
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);
57 cct->do_command("config diff get", cmdmap, "xml", &out);
58 string s(out.c_str(), out.length());
59 EXPECT_EQ("<config_diff_get><diff><current><key>" + value +
60 "</key></current><defaults><key></key></defaults></diff></config_diff_get>", s);
65 TEST(CephContext, experimental_features)
67 CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get();
69 cct->_conf->cluster = "ceph";
71 ASSERT_FALSE(cct->check_experimental_feature_enabled("foo"));
72 ASSERT_FALSE(cct->check_experimental_feature_enabled("bar"));
73 ASSERT_FALSE(cct->check_experimental_feature_enabled("baz"));
75 cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features",
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"));
82 cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features",
84 cct->_conf->apply_changes(&cout);
85 ASSERT_TRUE(cct->check_experimental_feature_enabled("foo"));
86 ASSERT_TRUE(cct->check_experimental_feature_enabled("bar"));
87 ASSERT_FALSE(cct->check_experimental_feature_enabled("baz"));
89 cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features",
91 cct->_conf->apply_changes(&cout);
92 ASSERT_TRUE(cct->check_experimental_feature_enabled("foo"));
93 ASSERT_FALSE(cct->check_experimental_feature_enabled("bar"));
94 ASSERT_TRUE(cct->check_experimental_feature_enabled("baz"));
96 cct->_conf->set_val("enable_experimental_unrecoverable_data_corrupting_features",
98 cct->_conf->apply_changes(&cout);
99 ASSERT_TRUE(cct->check_experimental_feature_enabled("foo"));
100 ASSERT_TRUE(cct->check_experimental_feature_enabled("bar"));
101 ASSERT_TRUE(cct->check_experimental_feature_enabled("baz"));
108 * compile-command: "cd ../.. ;
109 * make unittest_context &&
111 * --max-stackframe=20000000 --tool=memcheck \
112 * ./unittest_context # --gtest_filter=CephContext.*