mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 11:59:00 +08:00
add web_impl util unittest (#2886)
* add testcase of empty vector insert Signed-off-by: godchen0212 <qingxiang.chen@zilliz.com> * format python code Signed-off-by: godchen0212 <qingxiang.chen@zilliz.com> * add web_impl util unittest Signed-off-by: godchen0212 <qingxiang.chen@zilliz.com> * format code Signed-off-by: godchen0212 <qingxiang.chen@zilliz.com> * format code Signed-off-by: godchen0212 <qingxiang.chen@zilliz.com>
This commit is contained in:
parent
9efddeee15
commit
c083556189
@ -10,6 +10,7 @@
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
#include "server/web_impl/utils/Util.h"
|
||||
#include <fiu-local.h>
|
||||
|
||||
#include "utils/ValidationUtil.h"
|
||||
|
||||
@ -20,6 +21,7 @@ namespace web {
|
||||
Status
|
||||
ParseQueryInteger(const OQueryParams& query_params, const std::string& key, int64_t& value, bool nullable) {
|
||||
auto query = query_params.get(key.c_str());
|
||||
fiu_do_on("WebUtils.ParseQueryInteger.null_query_get", query = "");
|
||||
if (nullptr != query.get() && query->getSize() > 0) {
|
||||
std::string value_str = query->std_str();
|
||||
if (!ValidationUtil::ValidateStringIsNumber(value_str).ok()) {
|
||||
@ -38,6 +40,7 @@ ParseQueryInteger(const OQueryParams& query_params, const std::string& key, int6
|
||||
Status
|
||||
ParseQueryStr(const OQueryParams& query_params, const std::string& key, std::string& value, bool nullable) {
|
||||
auto query = query_params.get(key.c_str());
|
||||
fiu_do_on("WebUtils.ParseQueryStr.null_query_get", query = "");
|
||||
if (nullptr != query.get() && query->getSize() > 0) {
|
||||
value = query->std_str();
|
||||
} else if (!nullable) {
|
||||
@ -50,6 +53,7 @@ ParseQueryStr(const OQueryParams& query_params, const std::string& key, std::str
|
||||
Status
|
||||
ParseQueryBool(const OQueryParams& query_params, const std::string& key, bool& value, bool nullable) {
|
||||
auto query = query_params.get(key.c_str());
|
||||
fiu_do_on("WebUtils.ParseQueryBool.null_query_get", query = "");
|
||||
if (nullptr != query.get() && query->getSize() > 0) {
|
||||
std::string value_str = query->std_str();
|
||||
if (!ValidationUtil::ValidateStringIsBool(value_str).ok()) {
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "server/web_impl/dto/StatusDto.hpp"
|
||||
#include "server/web_impl/dto/VectorDto.hpp"
|
||||
#include "server/web_impl/handler/WebRequestHandler.h"
|
||||
#include "server/web_impl/utils/Util.h"
|
||||
#include "src/version.h"
|
||||
#include "utils/CommonUtil.h"
|
||||
#include "utils/StringHelpFunctions.h"
|
||||
@ -1549,3 +1550,125 @@ TEST_F(WebControllerTest, LOAD) {
|
||||
ASSERT_EQ(OStatus::CODE_400.code, response->getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
class WebUtilTest : public ::testing::Test {
|
||||
public:
|
||||
std::string key;
|
||||
OString value;
|
||||
int64_t intValue;
|
||||
std::string stringValue;
|
||||
bool boolValue;
|
||||
OQueryParams params;
|
||||
|
||||
void
|
||||
SetUp() override {
|
||||
key = "offset";
|
||||
}
|
||||
|
||||
void
|
||||
TearDown() override {
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
TEST_F(WebUtilTest, ParseQueryInteger) {
|
||||
value = "5";
|
||||
|
||||
params.put("offset", value);
|
||||
milvus::Status status = milvus::server::web::ParseQueryInteger(params, key, intValue);
|
||||
ASSERT_TRUE(status.ok());
|
||||
ASSERT_EQ(5, intValue);
|
||||
|
||||
}
|
||||
|
||||
TEST_F(WebUtilTest, ParQueryIntegerIllegalQueryParam) {
|
||||
value = "-5";
|
||||
|
||||
params.put("offset", value);
|
||||
milvus::Status status = milvus::server::web::ParseQueryInteger(params, key, intValue);
|
||||
ASSERT_EQ(status.code(), milvus::server::web::ILLEGAL_QUERY_PARAM);
|
||||
ASSERT_STREQ(status.message().c_str(),
|
||||
"Query param \'offset\' is illegal, only non-negative integer supported");
|
||||
|
||||
}
|
||||
|
||||
TEST_F(WebUtilTest, ParQueryIntegerQueryParamLoss) {
|
||||
value = "5";
|
||||
|
||||
params.put("offset", value);
|
||||
fiu_enable("WebUtils.ParseQueryInteger.null_query_get", 1, nullptr, 0);
|
||||
milvus::Status status = milvus::server::web::ParseQueryInteger(params, key, intValue, false);
|
||||
ASSERT_EQ(status.code(), milvus::server::web::QUERY_PARAM_LOSS);
|
||||
std::string msg = "Query param \"" + key + "\" is required";
|
||||
ASSERT_STREQ(status.message().c_str(), msg.c_str());
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST_F(WebUtilTest, ParseQueryBoolTrue) {
|
||||
value = "True";
|
||||
|
||||
params.put("offset", value);
|
||||
milvus::Status status = milvus::server::web::ParseQueryBool(params, key, boolValue);
|
||||
ASSERT_TRUE(status.ok());
|
||||
ASSERT_TRUE(boolValue);
|
||||
|
||||
}
|
||||
|
||||
TEST_F(WebUtilTest, ParQueryBoolFalse) {
|
||||
|
||||
value = "False";
|
||||
|
||||
params.put("offset", value);
|
||||
milvus::Status status = milvus::server::web::ParseQueryBool(params, key, boolValue);
|
||||
ASSERT_TRUE(status.ok());
|
||||
ASSERT_TRUE(!boolValue);
|
||||
|
||||
}
|
||||
|
||||
TEST_F(WebUtilTest, ParQueryBoolIllegalQuery) {
|
||||
|
||||
value = "Hello";
|
||||
|
||||
params.put("offset", value);
|
||||
milvus::Status status = milvus::server::web::ParseQueryBool(params, key, boolValue);
|
||||
ASSERT_EQ(status.code(), milvus::server::web::ILLEGAL_QUERY_PARAM);
|
||||
ASSERT_STREQ(status.message().c_str(), "Query param \'all_required\' must be a bool");
|
||||
|
||||
}
|
||||
|
||||
TEST_F(WebUtilTest, ParQueryBoolQueryParamLoss) {
|
||||
|
||||
value = "Hello";
|
||||
|
||||
params.put("offset", value);
|
||||
fiu_enable("WebUtils.ParseQueryBool.null_query_get", 1, nullptr, 0);
|
||||
milvus::Status status = milvus::server::web::ParseQueryBool(params, key, boolValue, false);
|
||||
ASSERT_EQ(status.code(), milvus::server::web::QUERY_PARAM_LOSS);
|
||||
std::string msg = "Query param \"" + key + "\" is required";
|
||||
ASSERT_STREQ(status.message().c_str(), msg.c_str());
|
||||
|
||||
}
|
||||
|
||||
TEST_F(WebUtilTest, ParseQueryStr) {
|
||||
value = "Are you ok?";
|
||||
|
||||
params.put("offset", value);
|
||||
milvus::Status status = milvus::server::web::ParseQueryStr(params, key, stringValue);
|
||||
ASSERT_TRUE(status.ok());
|
||||
ASSERT_STREQ(value->c_str(), stringValue.c_str());
|
||||
|
||||
}
|
||||
|
||||
TEST_F(WebUtilTest, ParQueryStrQueryParamLoss) {
|
||||
|
||||
value = "Are you ok?";
|
||||
|
||||
params.put("offset", value);
|
||||
fiu_enable("WebUtils.ParseQueryStr.null_query_get", 1, nullptr, 0);
|
||||
milvus::Status status = milvus::server::web::ParseQueryStr(params, key, stringValue, false);
|
||||
ASSERT_EQ(status.code(), milvus::server::web::QUERY_PARAM_LOSS);
|
||||
std::string msg = "Query param \"" + key + "\" is required";
|
||||
ASSERT_STREQ(status.message().c_str(), msg.c_str());
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user