node tags test

This commit is contained in:
fengzero
2026-01-21 02:35:18 +00:00
parent 4a13b39ec6
commit ebc11baafd
4 changed files with 76 additions and 7 deletions
+5 -7
View File
@@ -690,10 +690,6 @@ void handle_put_node_tag(nng_aio *aio)
NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
aio, neu_json_update_node_tag_req_t,
neu_json_decode_update_node_tag_req, {
int ret = 0;
neu_reqresp_head_t header = { 0 };
neu_req_update_node_tag_t cmd = { 0 };
if (req->tags != NULL && !tags_check_symbol(req->tags)) {
NEU_JSON_RESPONSE_ERROR(NEU_ERR_NODE_TAGS_INVALID, {
neu_http_response(aio, error_code.error, result_error);
@@ -704,11 +700,13 @@ void handle_put_node_tag(nng_aio *aio)
});
neu_json_decode_update_node_tag_req_free(req);
} else {
header.ctx = aio;
header.type = NEU_REQ_UPDATE_NODE_TAG;
neu_reqresp_head_t header = { 0 };
neu_req_update_node_tag_t cmd = { 0 };
header.ctx = aio;
header.type = NEU_REQ_UPDATE_NODE_TAG;
strcpy(cmd.node, req->name);
strcpy(cmd.tags, req->tags);
ret = neu_plugin_op(plugin, header, &cmd);
int ret = neu_plugin_op(plugin, header, &cmd);
if (ret != 0) {
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
neu_http_response(aio, NEU_ERR_IS_BUSY, result_error);
+13
View File
@@ -68,6 +68,19 @@ def add_node(node, plugin, params=None, jwt=config.default_jwt):
body["params"] = params
return requests.post(url=config.BASE_URL + '/api/v2/node', headers={"Authorization": jwt}, json=body)
@gen_check
def add_node_with_tags(node, plugin, tags=None, params=None, jwt=config.default_jwt):
body = {"name": node, "plugin": plugin}
if params:
body["params"] = params
if tags:
body["tags"] = tags
return requests.post(url=config.BASE_URL + '/api/v2/node', headers={"Authorization": jwt}, json=body)
@gen_check
def update_node_tags(node, tags, jwt=config.default_jwt):
return requests.put(url=config.BASE_URL + '/api/v2/node/tag', headers={"Authorization": jwt}, json={"name": node, "tags": tags})
@gen_check
def update_node(node, new_name, jwt=config.default_jwt):
+3
View File
@@ -33,6 +33,9 @@ NEU_ERR_NODE_NOT_ALLOW_SUBSCRIBE = 2012
NEU_ERR_NODE_NOT_ALLOW_UPDATE = 2013
NEU_ERR_NODE_NOT_ALLOW_MAP = 2014
NEU_ERR_NODE_NAME_EMPTY = 2015
NEU_ERR_NODE_TAGS_TOO_LONG = 2016
NEU_ERR_NODE_TAGS_TOO_MANY = 2017
NEU_ERR_NODE_TAGS_INVALID = 2018
NEU_ERR_GROUP_ALREADY_SUBSCRIBED = 2101
NEU_ERR_GROUP_NOT_SUBSCRIBE = 2102
+55
View File
@@ -0,0 +1,55 @@
import neuron.api as api
from neuron.config import *
from neuron.common import *
from neuron.error import *
class TestNodeTag:
@description(given="existent driver node", when="add tags to the node", then="add success")
def test_add_tags_to_node(self):
response = api.add_node_with_tags(node="modbus-tcp", plugin=PLUGIN_MODBUS_TCP, tags="tag1,tag2")
assert 200 == response.status_code
assert NEU_ERR_SUCCESS == response.json()['error']
response = api.get_nodes(type=1)
assert 200 == response.status_code
assert "tag1,tag2" == response.json()['nodes'][0]['tags']
@description(given="existent driver node with tags", when="update tags of the node", then="update success")
def test_update_tags_of_node(self):
response = api.update_node_tags(node="modbus-tcp", tags="tag3,tag4,tag5")
assert 200 == response.status_code
assert NEU_ERR_SUCCESS == response.json()['error']
response = api.get_nodes(type=1)
assert 200 == response.status_code
assert "tag3,tag4,tag5" == response.json()['nodes'][0]['tags']
@description(given="existent driver node with tags", when="update tags of the node to empty", then="update success")
def test_update_tags_of_node_to_empty(self):
response = api.update_node_tags(node="modbus-tcp", tags="")
assert 200 == response.status_code
assert NEU_ERR_SUCCESS == response.json()['error']
response = api.get_nodes(type=1)
assert 200 == response.status_code
assert "" == response.json()['nodes'][0]['tags']
@description(given="existent driver node", when="add tags with invalid symbol", then="add failed")
def test_add_tags_with_invalid_symbol(self):
response = api.add_node_with_tags(node="modbus-tcp-2", plugin=PLUGIN_MODBUS_TCP, tags="tag1,tag@2")
assert 400 == response.status_code
assert NEU_ERR_NODE_TAGS_INVALID == response.json()['error']
@description(given="existent driver node", when="update tags with invalid symbol", then="update failed")
def test_update_tags_with_invalid_symbol(self):
response = api.add_node(node="modbus-tcp-2", plugin=PLUGIN_MODBUS_TCP)
assert 200 == response.status_code
assert NEU_ERR_SUCCESS == response.json()['error']
response = api.update_node_tags(node="modbus-tcp-2", tags="tag#3,tag4")
assert 400 == response.status_code
assert NEU_ERR_NODE_TAGS_INVALID == response.json()['error']
@description(given="existent driver node", when="add tags exceeding the limit", then="add failed")
def test_add_tags_exceeding_limit(self):
response = api.add_node_with_tags(node="modbus-tcp-3", plugin=PLUGIN_MODBUS_TCP, tags="tag1,tag2,tag3,tag4,tag5,tag6")
assert 400 == response.status_code
assert NEU_ERR_NODE_TAGS_TOO_MANY == response.json()['error']