mirror of
https://github.com/emqx/neuron.git
synced 2026-10-29 15:09:11 +08:00
fix build warning
This commit is contained in:
@@ -93,6 +93,7 @@ static int dump_value(property_json_buffer_t *buffer, const json_t *value)
|
||||
return -1;
|
||||
}
|
||||
first = false;
|
||||
(void) first;
|
||||
}
|
||||
return append(buffer, "}");
|
||||
}
|
||||
|
||||
+3
-3
@@ -313,8 +313,8 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
neu_resp_error_t e = { .error = NEU_ERR_NODE_NOT_EXIST };
|
||||
|
||||
if (neu_node_manager_find(manager->node_manager, cmd->node) != NULL) {
|
||||
e.error = neu_persister_update_node_property(cmd->node,
|
||||
&cmd->property);
|
||||
e.error =
|
||||
neu_persister_update_node_property(cmd->node, &cmd->property);
|
||||
}
|
||||
neu_req_update_node_property_fini(cmd);
|
||||
header->type = NEU_RESP_ERROR;
|
||||
@@ -326,7 +326,7 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
neu_req_get_node_properties_t *cmd =
|
||||
(neu_req_get_node_properties_t *) &header[1];
|
||||
neu_resp_get_node_properties_t resp = { 0 };
|
||||
neu_resp_error_t e = { .error = NEU_ERR_NODE_NOT_EXIST };
|
||||
neu_resp_error_t e = { .error = NEU_ERR_NODE_NOT_EXIST };
|
||||
|
||||
if (neu_node_manager_find(manager->node_manager, cmd->node) != NULL) {
|
||||
e.error = neu_persister_load_node_properties(
|
||||
|
||||
@@ -244,7 +244,7 @@ class TestPlugin:
|
||||
assert 200 == response.status_code
|
||||
for plugin in response.json().get("plugins"):
|
||||
if plugin['name'] == 'c1':
|
||||
assert plugin['version'] == '2.16.99'
|
||||
assert plugin['version'] == '2.15.99'
|
||||
|
||||
@description(given="incorrect configuration", when="update plugin", then="fail")
|
||||
def test_10_update_plugin_fail3(self):
|
||||
|
||||
+14
-12
@@ -10,7 +10,7 @@ class DriverCacheSample : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
cache = neu_driver_cache_new();
|
||||
cache = neu_driver_cache_new();
|
||||
neu_dvalue_t initial = {};
|
||||
initial.type = NEU_TYPE_ERROR;
|
||||
neu_driver_cache_add(cache, "group", "tag", initial);
|
||||
@@ -36,8 +36,8 @@ protected:
|
||||
|
||||
bool update(neu_dvalue_t value)
|
||||
{
|
||||
return neu_driver_cache_update_change(cache, "group", "tag", 200,
|
||||
value, NULL, 0, false);
|
||||
return neu_driver_cache_update_change(cache, "group", "tag", 200, value,
|
||||
NULL, 0, false);
|
||||
}
|
||||
|
||||
int changed()
|
||||
@@ -46,10 +46,10 @@ protected:
|
||||
&metas, &n_meta);
|
||||
}
|
||||
|
||||
neu_driver_cache_t *cache = NULL;
|
||||
neu_driver_cache_value_t out = {};
|
||||
neu_tag_meta_t *metas = NULL;
|
||||
int n_meta = 0;
|
||||
neu_driver_cache_t * cache = NULL;
|
||||
neu_driver_cache_value_t out = {};
|
||||
neu_tag_meta_t * metas = NULL;
|
||||
int n_meta = 0;
|
||||
};
|
||||
|
||||
TEST_F(DriverCacheSample, existing_update_preserves_optional_attrs)
|
||||
@@ -60,8 +60,9 @@ TEST_F(DriverCacheSample, existing_update_preserves_optional_attrs)
|
||||
value.attrs.has_quality = flags & 2;
|
||||
neu_driver_cache_update(cache, "group", "tag", 200, value, NULL, 0);
|
||||
|
||||
ASSERT_EQ(0, neu_driver_cache_meta_get(cache, "group", "tag", &out,
|
||||
&metas, &n_meta));
|
||||
ASSERT_EQ(0,
|
||||
neu_driver_cache_meta_get(cache, "group", "tag", &out, &metas,
|
||||
&n_meta));
|
||||
EXPECT_EQ(200, out.timestamp);
|
||||
EXPECT_EQ(value.attrs.has_timestamp, out.value.attrs.has_timestamp);
|
||||
EXPECT_EQ(value.attrs.has_quality, out.value.attrs.has_quality);
|
||||
@@ -79,8 +80,9 @@ TEST_F(DriverCacheSample, timestamp_alone_does_not_trigger_change)
|
||||
value.attrs.timestamp++;
|
||||
EXPECT_FALSE(update(value));
|
||||
EXPECT_NE(0, changed());
|
||||
ASSERT_EQ(0, neu_driver_cache_meta_get(cache, "group", "tag", &out,
|
||||
&metas, &n_meta));
|
||||
ASSERT_EQ(0,
|
||||
neu_driver_cache_meta_get(cache, "group", "tag", &out, &metas,
|
||||
&n_meta));
|
||||
EXPECT_EQ(value.attrs.timestamp, out.value.attrs.timestamp);
|
||||
|
||||
value.attrs.has_timestamp = false;
|
||||
@@ -143,7 +145,7 @@ TEST_F(DriverCacheSample, forced_update_preserves_attrs)
|
||||
|
||||
TEST_F(DriverCacheSample, filtered_error_compares_last_good_quality)
|
||||
{
|
||||
sub_filter_err = true;
|
||||
sub_filter_err = true;
|
||||
neu_dvalue_t value = sample();
|
||||
ASSERT_TRUE(update(value));
|
||||
ASSERT_EQ(0, changed());
|
||||
|
||||
+94
-39
@@ -1,12 +1,12 @@
|
||||
#include <cmath>
|
||||
#include <gtest/gtest.h>
|
||||
#include <jansson.h>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "parser/neu_json_node.h"
|
||||
#include "utils/log.h"
|
||||
#include "json/json.h"
|
||||
#include "parser/neu_json_node.h"
|
||||
|
||||
zlog_category_t *neuron = NULL;
|
||||
TEST(JsonTest, DecodeField)
|
||||
@@ -338,13 +338,27 @@ namespace {
|
||||
using PropertyJson = std::unique_ptr<json_t, decltype(&json_decref)>;
|
||||
|
||||
const char *property_values[] = {
|
||||
R"("text")", R"("")", "true", "false", "0", "-1",
|
||||
"-9223372036854775808", "9223372036854775807", "9007199254740993",
|
||||
"1.25", "0.0", "-0.0", "1.7976931348623157e308",
|
||||
"2.2250738585072014e-308", "5e-324",
|
||||
R"(["", "中文", "a\"b", "a\u0000b"])", "[true, false]",
|
||||
R"("text")",
|
||||
R"("")",
|
||||
"true",
|
||||
"false",
|
||||
"0",
|
||||
"-1",
|
||||
"-9223372036854775808",
|
||||
"9223372036854775807",
|
||||
"9007199254740993",
|
||||
"1.25",
|
||||
"0.0",
|
||||
"-0.0",
|
||||
"1.7976931348623157e308",
|
||||
"2.2250738585072014e-308",
|
||||
"5e-324",
|
||||
R"(["", "中文", "a\"b", "a\u0000b"])",
|
||||
"[true, false]",
|
||||
"[-9223372036854775808, 0, 9223372036854775807]",
|
||||
"[0.0, -1.5, 2.5]", "[0, 1.5, -2, 0.0]", "[]",
|
||||
"[0.0, -1.5, 2.5]",
|
||||
"[0, 1.5, -2, 0.0]",
|
||||
"[]",
|
||||
R"("中文\"\\\n\r\t\b\f\u0000end")",
|
||||
};
|
||||
|
||||
@@ -368,8 +382,8 @@ void expect_property_json(const char *expected_text, const char *actual_text)
|
||||
|
||||
void expect_property_response(neu_node_property_t *properties, size_t count)
|
||||
{
|
||||
neu_json_get_node_properties_resp_t response = {count, properties};
|
||||
char *encoded = NULL;
|
||||
neu_json_get_node_properties_resp_t response = { count, properties };
|
||||
char * encoded = NULL;
|
||||
ASSERT_EQ(0, neu_json_encode_get_node_properties_resp(&response, &encoded));
|
||||
std::unique_ptr<char, decltype(&free)> buffer(encoded, free);
|
||||
ASSERT_NE(nullptr, buffer.get());
|
||||
@@ -386,7 +400,8 @@ void expect_property_response(neu_node_property_t *properties, size_t count)
|
||||
ASSERT_TRUE(json_is_string(json_object_get(item, "key")));
|
||||
EXPECT_STREQ(properties[i].key,
|
||||
json_string_value(json_object_get(item, "key")));
|
||||
char *value = neu_node_property_json_dump(json_object_get(item, "value"));
|
||||
char *value =
|
||||
neu_node_property_json_dump(json_object_get(item, "value"));
|
||||
ASSERT_NE(nullptr, value);
|
||||
expect_property_json(properties[i].value_json, value);
|
||||
free(value);
|
||||
@@ -398,18 +413,19 @@ void expect_property_response(neu_node_property_t *properties, size_t count)
|
||||
TEST(JsonTest, NodePropertiesAddAndResponsePreserveTypes)
|
||||
{
|
||||
const size_t count = sizeof(property_values) / sizeof(property_values[0]);
|
||||
std::string input = R"({"node":"driver","properties":[)";
|
||||
std::string input = R"({"node":"driver","properties":[)";
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
if (i != 0) {
|
||||
input += ",";
|
||||
}
|
||||
input += "{\"key\":\"key" + std::to_string(i) +
|
||||
"\",\"value\":" + property_values[i] + "}";
|
||||
"\",\"value\":" + property_values[i] + "}";
|
||||
}
|
||||
input += "]}";
|
||||
neu_json_add_node_properties_req_t *raw = NULL;
|
||||
ASSERT_EQ(0, neu_json_decode_add_node_properties_req(
|
||||
const_cast<char *>(input.c_str()), &raw));
|
||||
ASSERT_EQ(0,
|
||||
neu_json_decode_add_node_properties_req(
|
||||
const_cast<char *>(input.c_str()), &raw));
|
||||
std::unique_ptr<neu_json_add_node_properties_req_t,
|
||||
decltype(&neu_json_decode_add_node_properties_req_free)>
|
||||
request(raw, neu_json_decode_add_node_properties_req_free);
|
||||
@@ -419,7 +435,8 @@ TEST(JsonTest, NodePropertiesAddAndResponsePreserveTypes)
|
||||
for (size_t i = 0; i < request->n_property; ++i) {
|
||||
SCOPED_TRACE(property_values[i]);
|
||||
EXPECT_EQ("key" + std::to_string(i), request->properties[i].key);
|
||||
expect_property_json(property_values[i], request->properties[i].value_json);
|
||||
expect_property_json(property_values[i],
|
||||
request->properties[i].value_json);
|
||||
}
|
||||
expect_property_response(request->properties, request->n_property);
|
||||
}
|
||||
@@ -432,10 +449,12 @@ TEST(JsonTest, NodePropertyUpdateAndResponsePreserveTypes)
|
||||
input += value;
|
||||
input += "}";
|
||||
neu_json_update_node_property_req_t *raw = NULL;
|
||||
ASSERT_EQ(0, neu_json_decode_update_node_property_req(
|
||||
const_cast<char *>(input.c_str()), &raw));
|
||||
ASSERT_EQ(0,
|
||||
neu_json_decode_update_node_property_req(
|
||||
const_cast<char *>(input.c_str()), &raw));
|
||||
std::unique_ptr<neu_json_update_node_property_req_t,
|
||||
decltype(&neu_json_decode_update_node_property_req_free)>
|
||||
decltype(
|
||||
&neu_json_decode_update_node_property_req_free)>
|
||||
request(raw, neu_json_decode_update_node_property_req_free);
|
||||
ASSERT_NE(nullptr, request.get());
|
||||
EXPECT_STREQ("app", request->node);
|
||||
@@ -468,18 +487,33 @@ TEST(JsonTest, NodePropertiesDelete)
|
||||
TEST(JsonTest, NodePropertiesRejectInvalidValues)
|
||||
{
|
||||
const char *invalid[] = {
|
||||
"null", "{}", R"({"a":1})", "[[1]]", "[[]]", "[null]", "[{}]",
|
||||
R"([1,"1"])", "[true,1]", "[false,0.0]", R"(["true",true])",
|
||||
"9223372036854775808", "-9223372036854775809", "1e309", "NaN", "Infinity",
|
||||
"null",
|
||||
"{}",
|
||||
R"({"a":1})",
|
||||
"[[1]]",
|
||||
"[[]]",
|
||||
"[null]",
|
||||
"[{}]",
|
||||
R"([1,"1"])",
|
||||
"[true,1]",
|
||||
"[false,0.0]",
|
||||
R"(["true",true])",
|
||||
"9223372036854775808",
|
||||
"-9223372036854775809",
|
||||
"1e309",
|
||||
"NaN",
|
||||
"Infinity",
|
||||
};
|
||||
for (const char *value : invalid) {
|
||||
SCOPED_TRACE(value);
|
||||
std::string add = R"({"node":"driver","properties":[{"key":"valid","value":0},{"key":"bad","value":)";
|
||||
std::string add =
|
||||
R"({"node":"driver","properties":[{"key":"valid","value":0},{"key":"bad","value":)";
|
||||
add += value;
|
||||
add += "}]}";
|
||||
neu_json_add_node_properties_req_t *add_req = NULL;
|
||||
EXPECT_NE(0, neu_json_decode_add_node_properties_req(
|
||||
const_cast<char *>(add.c_str()), &add_req));
|
||||
EXPECT_NE(0,
|
||||
neu_json_decode_add_node_properties_req(
|
||||
const_cast<char *>(add.c_str()), &add_req));
|
||||
EXPECT_EQ(nullptr, add_req);
|
||||
neu_json_decode_add_node_properties_req_free(add_req);
|
||||
|
||||
@@ -487,8 +521,9 @@ TEST(JsonTest, NodePropertiesRejectInvalidValues)
|
||||
update += value;
|
||||
update += "}";
|
||||
neu_json_update_node_property_req_t *update_req = NULL;
|
||||
EXPECT_NE(0, neu_json_decode_update_node_property_req(
|
||||
const_cast<char *>(update.c_str()), &update_req));
|
||||
EXPECT_NE(0,
|
||||
neu_json_decode_update_node_property_req(
|
||||
const_cast<char *>(update.c_str()), &update_req));
|
||||
EXPECT_EQ(nullptr, update_req);
|
||||
neu_json_decode_update_node_property_req_free(update_req);
|
||||
}
|
||||
@@ -497,7 +532,11 @@ TEST(JsonTest, NodePropertiesRejectInvalidValues)
|
||||
TEST(JsonTest, NodePropertiesRejectInvalidAdd)
|
||||
{
|
||||
const char *invalid[] = {
|
||||
"", "{", "[]", "null", "{}",
|
||||
"",
|
||||
"{",
|
||||
"[]",
|
||||
"null",
|
||||
"{}",
|
||||
R"({"properties":[{"key":"a","value":0}]})",
|
||||
R"({"node":"","properties":[{"key":"a","value":0}]})",
|
||||
R"({"node":1,"properties":[{"key":"a","value":0}]})",
|
||||
@@ -521,8 +560,9 @@ TEST(JsonTest, NodePropertiesRejectInvalidAdd)
|
||||
for (const char *input : invalid) {
|
||||
SCOPED_TRACE(input);
|
||||
neu_json_add_node_properties_req_t *request = NULL;
|
||||
EXPECT_NE(0, neu_json_decode_add_node_properties_req(
|
||||
const_cast<char *>(input), &request));
|
||||
EXPECT_NE(0,
|
||||
neu_json_decode_add_node_properties_req(
|
||||
const_cast<char *>(input), &request));
|
||||
EXPECT_EQ(nullptr, request);
|
||||
neu_json_decode_add_node_properties_req_free(request);
|
||||
}
|
||||
@@ -531,13 +571,20 @@ TEST(JsonTest, NodePropertiesRejectInvalidAdd)
|
||||
TEST(JsonTest, NodePropertiesRejectInvalidDelete)
|
||||
{
|
||||
const char *invalid[] = {
|
||||
"", "{", "[]", "null", "{}", R"({"keys":["a"]})",
|
||||
"",
|
||||
"{",
|
||||
"[]",
|
||||
"null",
|
||||
"{}",
|
||||
R"({"keys":["a"]})",
|
||||
R"({"node":"","keys":["a"]})",
|
||||
R"({"node":null,"keys":["a"]})",
|
||||
R"({"node":1,"keys":["a"]})",
|
||||
R"({"node":"a\u0000b","keys":["a"]})",
|
||||
R"({"node":"app"})", R"({"node":"app","keys":[]})",
|
||||
R"({"node":"app","keys":null})", R"({"node":"app","keys":"a"})",
|
||||
R"({"node":"app"})",
|
||||
R"({"node":"app","keys":[]})",
|
||||
R"({"node":"app","keys":null})",
|
||||
R"({"node":"app","keys":"a"})",
|
||||
R"({"node":"app","keys":["valid",""]})",
|
||||
R"({"node":"app","keys":["valid",null]})",
|
||||
R"({"node":"app","keys":["valid",1]})",
|
||||
@@ -550,8 +597,9 @@ TEST(JsonTest, NodePropertiesRejectInvalidDelete)
|
||||
for (const char *input : invalid) {
|
||||
SCOPED_TRACE(input);
|
||||
neu_json_delete_node_properties_req_t *request = NULL;
|
||||
EXPECT_NE(0, neu_json_decode_delete_node_properties_req(
|
||||
const_cast<char *>(input), &request));
|
||||
EXPECT_NE(0,
|
||||
neu_json_decode_delete_node_properties_req(
|
||||
const_cast<char *>(input), &request));
|
||||
EXPECT_EQ(nullptr, request);
|
||||
neu_json_decode_delete_node_properties_req_free(request);
|
||||
}
|
||||
@@ -560,12 +608,18 @@ TEST(JsonTest, NodePropertiesRejectInvalidDelete)
|
||||
TEST(JsonTest, NodePropertiesRejectInvalidUpdate)
|
||||
{
|
||||
const char *invalid[] = {
|
||||
"", "{", "[]", "null", "{}", R"({"key":"a","value":0})",
|
||||
"",
|
||||
"{",
|
||||
"[]",
|
||||
"null",
|
||||
"{}",
|
||||
R"({"key":"a","value":0})",
|
||||
R"({"node":"","key":"a","value":0})",
|
||||
R"({"node":null,"key":"a","value":0})",
|
||||
R"({"node":1,"key":"a","value":0})",
|
||||
R"({"node":"a\u0000b","key":"a","value":0})",
|
||||
R"({"node":"app","value":0})", R"({"node":"app","key":"a"})",
|
||||
R"({"node":"app","value":0})",
|
||||
R"({"node":"app","key":"a"})",
|
||||
R"({"node":"app","key":"","value":0})",
|
||||
R"({"node":"app","key":false,"value":0})",
|
||||
R"({"node":"app","key":"a\u0000b","value":0})",
|
||||
@@ -574,8 +628,9 @@ TEST(JsonTest, NodePropertiesRejectInvalidUpdate)
|
||||
for (const char *input : invalid) {
|
||||
SCOPED_TRACE(input);
|
||||
neu_json_update_node_property_req_t *request = NULL;
|
||||
EXPECT_NE(0, neu_json_decode_update_node_property_req(
|
||||
const_cast<char *>(input), &request));
|
||||
EXPECT_NE(0,
|
||||
neu_json_decode_update_node_property_req(
|
||||
const_cast<char *>(input), &request));
|
||||
EXPECT_EQ(nullptr, request);
|
||||
neu_json_decode_update_node_property_req_free(request);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ protected:
|
||||
ASSERT_EQ(0, mkdir((directory + "/schemas").c_str(), 0700));
|
||||
std::filesystem::copy_file(
|
||||
std::string(NEU_PROPERTY_SCHEMA_DIR) +
|
||||
"/0123_2.16.0_node_properties.sql",
|
||||
directory + "/schemas/0123_2.16.0_node_properties.sql");
|
||||
"/0160_2.16.1_node_properties.sql",
|
||||
directory + "/schemas/0160_2.16.1_node_properties.sql");
|
||||
ASSERT_EQ(0, chdir(directory.c_str()));
|
||||
ASSERT_EQ(SQLITE_OK,
|
||||
sqlite3_open_v2("persistence/sqlite.db", &db,
|
||||
@@ -401,7 +401,7 @@ TEST_F(NodePropertyPersist, PersistenceReopenAndMigration)
|
||||
db = neu_persister_get_db();
|
||||
expect("driver", { { "key", "[true,false]" } });
|
||||
EXPECT_EQ(1,
|
||||
scalar("SELECT count(*) FROM migrations WHERE version='0123' AND "
|
||||
scalar("SELECT count(*) FROM migrations WHERE version='0160' AND "
|
||||
"dirty=0"));
|
||||
EXPECT_EQ(1, scalar("PRAGMA foreign_keys"));
|
||||
EXPECT_NE(nullptr, sqlite3_db_mutex(db));
|
||||
|
||||
Reference in New Issue
Block a user