netdog: Make net_config
unit tests reusable across versions
#2385
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue number:
Related to #2204
Description of changes:
It's probably easiest to read this PR by commit, since the second commit has a decent amount of noise from moving the
test_data
files around.As we add versions to
net_config
we need to be able to run the same set of unit tests across multiple versions. Net config versions are typically "additive", meaning that new versions add support for a new feature while continuing to support previous features. Rust's default test tooling doesn't allow parameterizing tests, and while one could loop over versions within a single test, the output of thecargo test
tooling is less than satisfactory since you get a single line for a test.The objectives:
cargo test
output must show a line for each network config version/testThis PR achieves the above objective by moving the actual test code into macros. Each macro contains a group of tests for a given feature. The macros are declarative and generate the appropriate test code, using the version as a key. Each macro's associated test data files are in a similarly named directory and templated, using the version.
Using the test macros in each net config version involves importing the macro inside the
#[cfg(test)]
block, and invoking it:The output includes a single line for each version and test. It would look like the following for a v1 and (not yet implemented) v2.
Commit messages:
Testing done:
Terms of contribution:
By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.