mirror of
https://github.com/ceph/ceph
synced 2024-12-17 17:05:42 +00:00
test: add a test for filter in cls hello
Signed-off-by: John Spray <john.spray@redhat.com>
This commit is contained in:
parent
60d51fc4a9
commit
2777438b36
@ -16,6 +16,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "include/rados/librados.hpp"
|
||||
#include "include/encoding.h"
|
||||
#include "test/librados/test.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -131,3 +132,54 @@ TEST(ClsHello, BadMethods) {
|
||||
|
||||
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
|
||||
}
|
||||
|
||||
TEST(ClsHello, Filter) {
|
||||
Rados cluster;
|
||||
std::string pool_name = get_temp_pool_name();
|
||||
ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
|
||||
IoCtx ioctx;
|
||||
cluster.ioctx_create(pool_name.c_str(), ioctx);
|
||||
|
||||
char buf[128];
|
||||
memset(buf, 0xcc, sizeof(buf));
|
||||
bufferlist obj_content;
|
||||
obj_content.append(buf, sizeof(buf));
|
||||
|
||||
std::string target_str = "content";
|
||||
|
||||
// Write xattr bare, no ::encod'ing
|
||||
bufferlist target_val;
|
||||
target_val.append(target_str);
|
||||
bufferlist nontarget_val;
|
||||
nontarget_val.append("rhubarb");
|
||||
|
||||
ASSERT_EQ(0, ioctx.write("has_xattr", obj_content, obj_content.length(), 0));
|
||||
ASSERT_EQ(0, ioctx.write("has_wrong_xattr", obj_content, obj_content.length(), 0));
|
||||
ASSERT_EQ(0, ioctx.write("no_xattr", obj_content, obj_content.length(), 0));
|
||||
|
||||
ASSERT_EQ(0, ioctx.setxattr("has_xattr", "theattr", target_val));
|
||||
ASSERT_EQ(0, ioctx.setxattr("has_wrong_xattr", "theattr", nontarget_val));
|
||||
|
||||
bufferlist filter_bl;
|
||||
std::string filter_name = "hello.hello";
|
||||
::encode(filter_name, filter_bl);
|
||||
::encode("_theattr", filter_bl);
|
||||
::encode(target_str, filter_bl);
|
||||
|
||||
NObjectIterator iter(ioctx.nobjects_begin(filter_bl));
|
||||
bool foundit = false;
|
||||
int k = 0;
|
||||
while (iter != ioctx.nobjects_end()) {
|
||||
foundit = true;
|
||||
// We should only see the object that matches the filter
|
||||
ASSERT_EQ((*iter).get_oid(), "has_xattr");
|
||||
// We should only see it once
|
||||
ASSERT_EQ(k, 0);
|
||||
++iter;
|
||||
++k;
|
||||
}
|
||||
ASSERT_TRUE(foundit);
|
||||
|
||||
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user