summaryrefslogtreecommitdiffstats
path: root/src/test/libcephfs_config.cc
blob: a54bb4ddfe840cd53415d065ec4201a0eb6f5815 (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
// -*- 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) 2011 New Dream Network
 *
 * 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 "gtest/gtest.h"
#include "include/compat.h"
#include "include/cephfs/libcephfs.h"

#include <sstream>
#include <string>
#include <string.h>

using std::string;

TEST(LibCephConfig, SimpleSet) {
  struct ceph_mount_info *cmount;
  int ret = ceph_create(&cmount, NULL);
  ASSERT_EQ(ret, 0);

  ret = ceph_conf_set(cmount, "leveldb_max_open_files", "21");
  ASSERT_EQ(ret, 0);

  char buf[128];
  memset(buf, 0, sizeof(buf));
  ret = ceph_conf_get(cmount, "leveldb_max_open_files", buf, sizeof(buf));
  ASSERT_EQ(ret, 0);
  ASSERT_EQ(string("21"), string(buf));

  ceph_shutdown(cmount);
}

TEST(LibCephConfig, ArgV) {
  struct ceph_mount_info *cmount;
  int ret = ceph_create(&cmount, NULL);
  ASSERT_EQ(ret, 0);

  const char *argv[] = { "foo", "--leveldb-max-open-files", "2",
			 "--key", "my-key", NULL };
  size_t argc = (sizeof(argv) / sizeof(argv[0])) - 1;
  ceph_conf_parse_argv(cmount, argc, argv);

  char buf[128];
  memset(buf, 0, sizeof(buf));
  ret = ceph_conf_get(cmount, "key", buf, sizeof(buf));
  ASSERT_EQ(ret, 0);
  ASSERT_EQ(string("my-key"), string(buf));

  memset(buf, 0, sizeof(buf));
  ret = ceph_conf_get(cmount, "leveldb_max_open_files", buf, sizeof(buf));
  ASSERT_EQ(ret, 0);
  ASSERT_EQ(string("2"), string(buf));

  ceph_shutdown(cmount);
}