diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/src/document_store.cpp index f354a632baa0df92c58660299a1bff6c3b0d1109..98b7031131e4c0706d89208885a9cea3b9b6dd72 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/src/interface/src/document_store.cpp @@ -89,7 +89,7 @@ int DocumentStore::DropCollection(const std::string &name, int flags) return -E_INVALID_ARGS; } - bool ignoreNonExists = (flags == CHK_NON_EXIST_COLLECTION); + bool ignoreNonExists = (flags != CHK_NON_EXIST_COLLECTION); errCode = executor_->DropCollection(lowerCaseName, ignoreNonExists); if (errCode != E_OK) { GLOGE("Drop collection failed. %d", errCode); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/documentdb_collection_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/documentdb_collection_test.cpp index 5614bb41518ce7c9093cc6ae9f04696f4d963769..a15df4df50029f45055142b9ed59b2bc9d47c19f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/documentdb_collection_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_Simple/test/unittest/api/documentdb_collection_test.cpp @@ -89,17 +89,28 @@ const int MAX_COLLECTION_LEN = 512; HWTEST_F(DocumentDBCollectionTest, CollectionTest002, TestSize.Level0) { string overLenName(MAX_COLLECTION_LEN, 'a'); + EXPECT_EQ(GRD_CreateCollection(g_db, overLenName.c_str(), "", 0), GRD_OVER_LIMIT); + EXPECT_EQ(GRD_DropCollection(g_db, overLenName.c_str(), 0), GRD_OVER_LIMIT); + std::vector invalidName = { nullptr, "", + }; + + for (auto *it : invalidName) { + GLOGD("CollectionTest002: create collection with name: %s", it); + EXPECT_EQ(GRD_CreateCollection(g_db, it, "", 0), GRD_INVALID_ARGS); + EXPECT_EQ(GRD_DropCollection(g_db, it, 0), GRD_INVALID_ARGS); + } + + std::vector invalidNameFormat = { "GRD_123", "grd_123", "GM_SYS_123", - "gm_sys_123", - overLenName.c_str() + "gm_sys_123" }; - for (auto *it : invalidName) { + for (auto *it : invalidNameFormat) { GLOGD("CollectionTest002: create collection with name: %s", it); EXPECT_EQ(GRD_CreateCollection(g_db, it, "", 0), GRD_INVALID_FORMAT); EXPECT_EQ(GRD_DropCollection(g_db, it, 0), GRD_INVALID_FORMAT); @@ -186,8 +197,8 @@ HWTEST_F(DocumentDBCollectionTest, CollectionTest006, TestSize.Level0) EXPECT_EQ(GRD_CreateCollection(g_db, "student", R""({"maxDoc":2048})"", 0), GRD_INVALID_ARGS); EXPECT_EQ(GRD_DropCollection(g_db, "student", 0), GRD_OK); - EXPECT_EQ(GRD_DropCollection(g_db, "student", 0), GRD_NO_DATA); - EXPECT_EQ(GRD_DropCollection(g_db, "student", CHK_NON_EXIST_COLLECTION), GRD_OK); + EXPECT_EQ(GRD_DropCollection(g_db, "student", 0), GRD_OK); + EXPECT_EQ(GRD_DropCollection(g_db, "student", CHK_NON_EXIST_COLLECTION), GRD_NO_DATA); // Create collection with different option returnh OK after drop collection EXPECT_EQ(GRD_CreateCollection(g_db, "student", R""({"maxDoc":2048})"", 0), GRD_OK);