Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / libcephfs_config.cc
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) 2011 New Dream Network
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  *
13  */
14
15 #include "gtest/gtest.h"
16 #include "include/cephfs/libcephfs.h"
17
18 #include <sstream>
19 #include <string>
20 #include <string.h>
21
22 using std::string;
23
24 TEST(LibCephConfig, SimpleSet) {
25   struct ceph_mount_info *cmount;
26   int ret = ceph_create(&cmount, NULL);
27   ASSERT_EQ(ret, 0);
28
29   ret = ceph_conf_set(cmount, "leveldb_max_open_files", "21");
30   ASSERT_EQ(ret, 0);
31
32   char buf[128];
33   memset(buf, 0, sizeof(buf));
34   ret = ceph_conf_get(cmount, "leveldb_max_open_files", buf, sizeof(buf));
35   ASSERT_EQ(ret, 0);
36   ASSERT_EQ(string("21"), string(buf));
37
38   ceph_shutdown(cmount);
39 }
40
41 TEST(LibCephConfig, ArgV) {
42   struct ceph_mount_info *cmount;
43   int ret = ceph_create(&cmount, NULL);
44   ASSERT_EQ(ret, 0);
45
46   const char *argv[] = { "foo", "--leveldb-max-open-files", "2",
47                          "--keyfile", "/tmp/my-keyfile", NULL };
48   size_t argc = (sizeof(argv) / sizeof(argv[0])) - 1;
49   ceph_conf_parse_argv(cmount, argc, argv);
50
51   char buf[128];
52   memset(buf, 0, sizeof(buf));
53   ret = ceph_conf_get(cmount, "keyfile", buf, sizeof(buf));
54   ASSERT_EQ(ret, 0);
55   ASSERT_EQ(string("/tmp/my-keyfile"), string(buf));
56
57   memset(buf, 0, sizeof(buf));
58   ret = ceph_conf_get(cmount, "leveldb_max_open_files", buf, sizeof(buf));
59   ASSERT_EQ(ret, 0);
60   ASSERT_EQ(string("2"), string(buf));
61
62   ceph_shutdown(cmount);
63 }