Closed onelson closed 3 years ago
Merging #5 (624f6eb) into main (69f6152) will increase coverage by
14.35%
. The diff coverage is85.71%
.
@@ Coverage Diff @@
## main #5 +/- ##
===========================================
+ Coverage 74.20% 88.56% +14.35%
===========================================
Files 5 6 +1
Lines 442 516 +74
===========================================
+ Hits 328 457 +129
+ Misses 114 59 -55
Impacted Files | Coverage Δ | |
---|---|---|
src/main.rs | 0.00% <0.00%> (ø) |
|
src/handlers/registry.rs | 93.10% <98.57%> (+93.10%) |
:arrow_up: |
src/handlers.rs | 100.00% <100.00%> (ø) |
|
src/package_index.rs | 94.81% <0.00%> (+0.28%) |
:arrow_up: |
src/errors.rs | 46.15% <0.00%> (+46.15%) |
:arrow_up: |
src/storage.rs | 100.00% <0.00%> (+100.00%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 69f6152...624f6eb. Read the comment docs.
The main aim here is to increase coverage since we took a hit with the addition of all the untested web server related code.
This diff adds what the actix-web docs refer to as "integration" tests, which are tests written from the point of view of a client sending requests to the web server.
In order to implement these tests, some minor refactors had to be made so our test service could be created consistently, each test running in its own sandbox (as far as the file system access goes.
A new
Settings
struct was added to hold the paths for the crate storage and index directories which can be constructed from env vars, or manually. This struct is shared with handlers with theData
extractor.This allows us to avoid repeatedly looking at env vars in code that will be tested, while also giving us a single source of truth for these paths.
Previously deeper env var reads were unwrapping/expecting since it was assumed
main()
would have already ensured the vars were set. This is not the case in tests, or at least it's antagonistic to use env vars in this situation.The tests for the publish endpoint use a payload captured via "spying" on the requests sent to the service by cargo. mitmproxy was used to capture the bytes for this request body.
With mitmproxy running, I ran
cargo publish
with theCARGO_HTTP_PROXY
env var set, then copied the "flow" file to thetest_data/
dir so we could useinclude_bytes!()
in our test code.