New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests for syscollector legacy decoder #15985
Conversation
merror("Invalid message. Type not found."); // LCOV_EXCL_LINE | ||
goto end; // LCOV_EXCL_LINE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we not testing this and ignoring instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is not posible to achieve this section of code, because the only one entry point for decoder_XXX functions is by call on DecodeSyscollector().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is possible but we would need to mock this json_type = cJSON_GetObjectItem(logJSON, "type");
it would affect the entire file and probably not worth it. The team may decide this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure we can't send a JSON without type
to force cJSON_GetObjectItem()
to return NULL?
it would affect the entire file and probably not worth it.
Wrapping this function directly would indeed generate too many changes. Every test should be updated.
The only thing I can think of is updating __wrap_cJSON_GetObjectItem()
to allow selecting when we want the real function and when we need the fake one.
Something like
if(test_mode) {
//fake method
...
return mock;
}
else {
//real method
__real_cJSON_GetObjectItem();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not apply changes around this, this is a candidate for refactoring, it doesn't make sense to pass a string for a check that is done from the caller. A boolean would suffice to identify the end message.
merror("Invalid message. Type not found."); // LCOV_EXCL_LINE | ||
goto end; // LCOV_EXCL_LINE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would normalize this message using the approach of the one above by adding the function name. The same for all cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactoring exceeds the scope of the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
\"timestamp\":\"2021/10/29 14:26:24\",\ | ||
\"inventory\":{\ | ||
\"board_serial\" : \"86\",\ | ||
\"cpu_name\" : \"87\",\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use a more representative example but not change requested.
\"type\":\"hotfix\",\ | ||
\"ID\":100,\ | ||
\"timestamp\":\"2021/10/29 14:26:24\",\ | ||
\"hotfix\":\"hotfix-version-test\"\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use a more representative example but not change requested.
\"ID\":100,\ | ||
\"timestamp\":\"2021/10/29 14:26:24\",\ | ||
\"iface\":{\ | ||
\"name\" : \"86\",\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use a more representative example but not change requested.
8db2785
to
6580a42
Compare
* Add 100% UT coverage on these functions: decode_netinfo() decode_osinfo() decode_hardware() decode_package() decode_hotfix() decode_port() decode_process()
6580a42
to
bb683c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GJ!
merror("Invalid message. Type not found."); // LCOV_EXCL_LINE | ||
goto end; // LCOV_EXCL_LINE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure we can't send a JSON without type
to force cJSON_GetObjectItem()
to return NULL?
it would affect the entire file and probably not worth it.
Wrapping this function directly would indeed generate too many changes. Every test should be updated.
The only thing I can think of is updating __wrap_cJSON_GetObjectItem()
to allow selecting when we want the real function and when we need the fake one.
Something like
if(test_mode) {
//fake method
...
return mock;
}
else {
//real method
__real_cJSON_GetObjectItem();
}
Description
Add 100% UT coverage on these functions:
decode_netinfo()
decode_osinfo()
decode_hardware()
decode_package()
decode_hotfix()
decode_port()
decode_process()
Tests