Skip to content

Commit

Permalink
Merge pull request #1761 from hxy7yx/v2.7-1
Browse files Browse the repository at this point in the history
fix: add_tags&add_gtags http resp code
  • Loading branch information
fengzeroz authored Dec 18, 2023
2 parents 1366631 + c81dbba commit ffdf1c7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions ft/tag_test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ft/template.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
7 changes: 4 additions & 3 deletions plugins/restful/datatag_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 7 additions & 9 deletions src/utils/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions tests/ft/driver/test_modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,27 +382,27 @@ def test_add_wrong_tags(self, param):
"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']

Expand Down Expand Up @@ -571,7 +571,7 @@ def test_update_wrong_tag(self, param):
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']

Expand Down
4 changes: 2 additions & 2 deletions tests/ft/tag/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def test_adding_gtags_type_err(self):
]
)

assert 200 == response.status_code
assert 400 == response.status_code
assert NEU_ERR_TAG_TYPE_NOT_SUPPORT == response.json()['error']

response = api.get_group()
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_adding_gtags_name_err(self):
]
)

assert 200 == response.status_code
assert 409 == response.status_code
assert NEU_ERR_TAG_NAME_CONFLICT == response.json()['error']

response = api.get_group()
Expand Down

0 comments on commit ffdf1c7

Please sign in to comment.