mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
fix:add_tags and add_gtags http resp code
This commit is contained in:
+2
-2
@@ -59,7 +59,7 @@ Add different types of tags to the group, it should return success
|
||||
Add a list of tags with errors, it should return the number of successful additions.
|
||||
${res}= Add Tags modbus-node group ${tag1},${tag2},${tag3},${tag4}
|
||||
|
||||
Check Response Status ${res} 200
|
||||
Check Response Status ${res} 409
|
||||
Check Error Code ${res} ${NEU_ERR_TAG_NAME_CONFLICT}
|
||||
Should Be Equal As Integers ${res}[index] 0
|
||||
|
||||
@@ -139,7 +139,7 @@ Delete tag from non-existent group, it should return success
|
||||
Update non-existent tag, it should return failure.
|
||||
${res}= Update Tags modbus-node group ${tag4}
|
||||
|
||||
Check Response Status ${res} 200
|
||||
Check Response Status ${res} 404
|
||||
Check Error Code ${res} ${NEU_ERR_TAG_NOT_EXIST}
|
||||
|
||||
${res}= Get Tags modbus-node group
|
||||
|
||||
+4
-4
@@ -96,7 +96,7 @@ Create a template with invalid tag type, it should fail.
|
||||
${groups} = Create List ${group}
|
||||
|
||||
${res} = Add Template ${g_template} ${g_plugin} ${groups}
|
||||
Check Response Status ${res} 206
|
||||
Check Response Status ${res} 400
|
||||
Check Error Code ${res} ${NEU_ERR_TAG_TYPE_NOT_SUPPORT}
|
||||
|
||||
[Teardown] Del Template ${g_template}
|
||||
@@ -108,7 +108,7 @@ Create a template with invalid tag address, it should fail.
|
||||
${groups} = Create List ${group}
|
||||
|
||||
${res} = Add Template ${g_template} ${g_plugin} ${groups}
|
||||
Check Response Status ${res} 206
|
||||
Check Response Status ${res} 400
|
||||
Check Error Code ${res} ${NEU_ERR_TAG_ADDRESS_FORMAT_INVALID}
|
||||
|
||||
[Teardown] Del Template ${g_template}
|
||||
@@ -802,7 +802,7 @@ Add tag with too long name to existing template group, it should fail.
|
||||
|
||||
&{tag} = New Tag From ${g_tag1} name=${g_long_str}
|
||||
${res} = Add Template Tags ${g_template} ${g_group1}[name] ${tag}
|
||||
Check Response Status ${res} 206
|
||||
Check Response Status ${res} 400
|
||||
Check Error Code ${res} ${NEU_ERR_TAG_NAME_TOO_LONG}
|
||||
|
||||
[Teardown] Del Template ${g_template}
|
||||
@@ -1026,7 +1026,7 @@ Update tag name to invalid value, it should fail.
|
||||
|
||||
&{tag} = New Tag From ${g_tag1} name=${g_long_str}
|
||||
${res} = Put Template Tags ${g_template} ${g_group1}[name] ${tag}
|
||||
Check Response Status ${res} 206
|
||||
Check Response Status ${res} 400
|
||||
Check Error Code ${res} ${NEU_ERR_TAG_NAME_TOO_LONG}
|
||||
|
||||
[Teardown] Del Template ${g_template}
|
||||
|
||||
@@ -92,7 +92,8 @@ void handle_add_tags_resp(nng_aio *aio, neu_resp_add_tag_t *resp)
|
||||
|
||||
neu_json_encode_by_fn(&res, neu_json_encode_au_tags_resp, &result);
|
||||
|
||||
neu_http_ok(aio, result);
|
||||
NEU_JSON_RESPONSE_ERROR(resp->error,
|
||||
{ neu_http_response(aio, resp->error, result); });
|
||||
free(result);
|
||||
}
|
||||
|
||||
@@ -183,8 +184,8 @@ void handle_add_gtags_resp(nng_aio *aio, neu_resp_add_tag_t *resp)
|
||||
res.index = resp->index;
|
||||
|
||||
neu_json_encode_by_fn(&res, neu_json_encode_au_gtags_resp, &result);
|
||||
|
||||
neu_http_ok(aio, result);
|
||||
NEU_JSON_RESPONSE_ERROR(resp->error,
|
||||
{ neu_http_response(aio, resp->error, result); });
|
||||
free(result);
|
||||
}
|
||||
|
||||
|
||||
+7
-9
@@ -348,6 +348,13 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content)
|
||||
case NEU_ERR_LIBRARY_NAME_NOT_CONFORM:
|
||||
case NEU_ERR_LIBRARY_CLIB_NOT_MATCH:
|
||||
case NEU_ERR_LIBRARY_ARCH_NOT_SUPPORT:
|
||||
case NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT:
|
||||
case NEU_ERR_TAG_TYPE_NOT_SUPPORT:
|
||||
case NEU_ERR_TAG_ADDRESS_FORMAT_INVALID:
|
||||
case NEU_ERR_TAG_DESCRIPTION_TOO_LONG:
|
||||
case NEU_ERR_TAG_PRECISION_INVALID:
|
||||
case NEU_ERR_TAG_NAME_TOO_LONG:
|
||||
case NEU_ERR_TAG_ADDRESS_TOO_LONG:
|
||||
status = NNG_HTTP_STATUS_BAD_REQUEST;
|
||||
break;
|
||||
case NEU_ERR_FILE_NOT_EXIST:
|
||||
@@ -383,15 +390,6 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content)
|
||||
case NEU_ERR_LIBRARY_SYSTEM_NOT_ALLOW_DEL:
|
||||
status = NNG_HTTP_STATUS_CONFLICT;
|
||||
break;
|
||||
case NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT:
|
||||
case NEU_ERR_TAG_TYPE_NOT_SUPPORT:
|
||||
case NEU_ERR_TAG_ADDRESS_FORMAT_INVALID:
|
||||
case NEU_ERR_TAG_DESCRIPTION_TOO_LONG:
|
||||
case NEU_ERR_TAG_PRECISION_INVALID:
|
||||
case NEU_ERR_TAG_NAME_TOO_LONG:
|
||||
case NEU_ERR_TAG_ADDRESS_TOO_LONG:
|
||||
status = NNG_HTTP_STATUS_PARTIAL_CONTENT;
|
||||
break;
|
||||
default:
|
||||
if (code >= NEU_ERR_PLUGIN_ERROR_START &&
|
||||
code <= NEU_ERR_PLUGIN_ERROR_END) {
|
||||
|
||||
@@ -382,27 +382,27 @@ class TestModbus:
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_BYTES}]
|
||||
|
||||
response = api.add_tags(node=param[0], group='group', tags=wrong_tag1)
|
||||
assert 200 == response.status_code
|
||||
assert 400 == response.status_code
|
||||
assert error.NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT == response.json()[
|
||||
'error']
|
||||
|
||||
response = api.add_tags(node=param[0], group='group', tags=wrong_tag2)
|
||||
assert 200 == response.status_code
|
||||
assert 400 == response.status_code
|
||||
assert error.NEU_ERR_TAG_TYPE_NOT_SUPPORT == response.json()[
|
||||
'error']
|
||||
|
||||
response = api.add_tags(node=param[0], group='group', tags=wrong_tag3)
|
||||
assert 200 == response.status_code
|
||||
assert 400 == response.status_code
|
||||
assert error.NEU_ERR_TAG_ADDRESS_FORMAT_INVALID == response.json()[
|
||||
'error']
|
||||
|
||||
response = api.add_tags(node=param[0], group='group', tags=wrong_tag4)
|
||||
assert 200 == response.status_code
|
||||
assert 400 == response.status_code
|
||||
assert error.NEU_ERR_TAG_ADDRESS_FORMAT_INVALID == response.json()[
|
||||
'error']
|
||||
|
||||
response = api.add_tags(node=param[0], group='group', tags=wrong_tag5)
|
||||
assert 200 == response.status_code
|
||||
assert 400 == response.status_code
|
||||
assert error.NEU_ERR_TAG_ADDRESS_FORMAT_INVALID == response.json()[
|
||||
'error']
|
||||
|
||||
@@ -571,7 +571,7 @@ class TestModbus:
|
||||
up_tag[0]['type'] = config.NEU_TYPE_BIT
|
||||
response = api.update_tags(
|
||||
node=param[0], group='group', tags=up_tag)
|
||||
assert 200 == response.status_code
|
||||
assert 400 == response.status_code
|
||||
assert error.NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT == response.json()[
|
||||
'error']
|
||||
|
||||
|
||||
@@ -279,7 +279,7 @@ class TestLog:
|
||||
]
|
||||
)
|
||||
|
||||
assert 200 == response.status_code
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_TAG_TYPE_NOT_SUPPORT == response.json()['error']
|
||||
|
||||
response = api.get_group()
|
||||
@@ -342,7 +342,7 @@ class TestLog:
|
||||
]
|
||||
)
|
||||
|
||||
assert 200 == response.status_code
|
||||
assert 409 == response.status_code
|
||||
assert NEU_ERR_TAG_NAME_CONFLICT == response.json()['error']
|
||||
|
||||
response = api.get_group()
|
||||
|
||||
Reference in New Issue
Block a user