mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 04:32:38 +08:00
Export + filter response must have no trailing newline.
This commit is contained in:
parent
aa62458e54
commit
40ca7e23f6
@ -102,5 +102,9 @@ Option<bool> stateful_export_docs(export_state_t* export_state, size_t batch_siz
|
||||
done = done && (current_offset == export_state->index_ids[i].first);
|
||||
}
|
||||
|
||||
if(done && !export_state->res_body->empty()) {
|
||||
export_state->res_body->pop_back();
|
||||
}
|
||||
|
||||
return Option<bool>(true);
|
||||
}
|
@ -34,7 +34,6 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TEST_F(CoreAPIUtilsTest, StatefulRemoveDocs) {
|
||||
Collection *coll1;
|
||||
|
||||
@ -497,3 +496,43 @@ TEST_F(CoreAPIUtilsTest, MultiSearchWithPresetShouldUsePresetForAuth) {
|
||||
ASSERT_EQ("bar", collections[1].collection);
|
||||
ASSERT_EQ(2, embedded_params_vec.size());
|
||||
}
|
||||
|
||||
TEST_F(CoreAPIUtilsTest, ExportWithFilter) {
|
||||
Collection *coll1;
|
||||
std::vector<field> fields = {field("title", field_types::STRING, false),
|
||||
field("points", field_types::INT32, false),};
|
||||
|
||||
coll1 = collectionManager.get_collection("coll1").get();
|
||||
if(coll1 == nullptr) {
|
||||
coll1 = collectionManager.create_collection("coll1", 2, fields, "points").get();
|
||||
}
|
||||
|
||||
for(size_t i=0; i<4; i++) {
|
||||
nlohmann::json doc;
|
||||
doc["id"] = std::to_string(i);
|
||||
doc["title"] = "Title " + std::to_string(i);
|
||||
doc["points"] = i;
|
||||
coll1->add(doc.dump());
|
||||
}
|
||||
|
||||
bool done;
|
||||
std::string res_body;
|
||||
|
||||
export_state_t export_state;
|
||||
coll1->get_filter_ids("points:>=0", export_state.index_ids);
|
||||
for(size_t i=0; i<export_state.index_ids.size(); i++) {
|
||||
export_state.offsets.push_back(0);
|
||||
}
|
||||
|
||||
export_state.collection = coll1;
|
||||
export_state.res_body = &res_body;
|
||||
|
||||
stateful_export_docs(&export_state, 2, done);
|
||||
ASSERT_FALSE(done);
|
||||
ASSERT_EQ('\n', export_state.res_body->back());
|
||||
|
||||
// should not have trailing newline character for the last line
|
||||
stateful_export_docs(&export_state, 2, done);
|
||||
ASSERT_TRUE(done);
|
||||
ASSERT_EQ('}', export_state.res_body->back());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user