swaggest / rest

Web services with OpenAPI and JSON Schema done quick in Go
https://pkg.go.dev/github.com/swaggest/rest
MIT License
362 stars 17 forks source link

Add hook to catch body mismatch in test helper #39

Closed vearutop closed 3 years ago

vearutop commented 3 years ago

In order to have an easy way to dump unexpected values on application side.

github-actions[bot] commented 3 years ago

Lines Of Code

Language Files Lines Code Comments Blanks Complexity Bytes
Go 77 5979 (+23) 4342 (+17) 404 (+1) 1233 (+5) 827 (+10) 141.2K (+561B)
Go (test) 33 3478 (+55) 2684 (+43) 89 (+2) 705 (+10) 95 96.4K (+1.7K)
github-actions[bot] commented 3 years ago

Unit Test Coverage

total: (statements) 81.7%

Coverage diff with base branch ```diff 93c93 < github.com/swaggest/rest/request/decoder.go formDataToURLValues 77.8% --- > github.com/swaggest/rest/request/decoder.go formDataToURLValues 66.7% 145,146c145,146 < github.com/swaggest/rest/resttest/client.go do 78.4% < github.com/swaggest/rest/resttest/client.go checkResponses 61.9% --- > github.com/swaggest/rest/resttest/client.go do 81.1% > github.com/swaggest/rest/resttest/client.go checkResponses 76.2% 156c156 < github.com/swaggest/rest/resttest/client.go ExpectResponseBody 40.0% --- > github.com/swaggest/rest/resttest/client.go ExpectResponseBody 80.0% 158c158 < github.com/swaggest/rest/resttest/client.go checkBody 38.9% --- > github.com/swaggest/rest/resttest/client.go checkBody 57.1% 167,168c167,169 < github.com/swaggest/rest/resttest/server.go ServeHTTP 75.0% < github.com/swaggest/rest/resttest/server.go checkRequest 78.6% --- > github.com/swaggest/rest/resttest/server.go ServeHTTP 80.8% > github.com/swaggest/rest/resttest/server.go checkBody 83.3% > github.com/swaggest/rest/resttest/server.go checkRequest 84.2% 180c181 < total: (statements) 81.0% --- > total: (statements) 81.7% ```
codecov[bot] commented 3 years ago

Codecov Report

Merging #39 (2410afc) into master (b7aa8a3) will increase coverage by 1.95%. The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #39      +/-   ##
==========================================
+ Coverage   72.92%   74.87%   +1.95%     
==========================================
  Files          26       26              
  Lines        1551     1393     -158     
==========================================
- Hits         1131     1043      -88     
+ Misses        266      214      -52     
+ Partials      154      136      -18     
Flag Coverage Δ
unittests 74.87% <75.00%> (+1.95%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
resttest/server.go 65.57% <57.14%> (+3.63%) :arrow_up:
chirouter/wrapper.go 100.00% <100.00%> (ø)
resttest/client.go 60.39% <100.00%> (+4.24%) :arrow_up:
request/decoder.go 71.42% <0.00%> (-5.72%) :arrow_down:

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 ac60f98...2410afc. Read the comment docs.

github-actions[bot] commented 3 years ago

Benchmark Result

Benchmark diff with base branch ``` name old time/op new time/op delta pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 1.51µs ± 1% 1.52µs ± 4% ~ (p=0.786 n=5+5) pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 863ns ± 3% 852ns ± 3% ~ (p=0.421 n=5+5) DecoderFunc_Decode-2 2.34µs ± 1% 2.42µs ± 2% +3.27% (p=0.008 n=5+5) Decoder_Decode_json-2 27.8µs ± 4% 27.4µs ± 2% ~ (p=0.548 n=5+5) Decoder_Decode_queryObject-2 6.02µs ± 1% 6.11µs ± 1% +1.41% (p=0.016 n=5+5) Decoder_Decode_jsonParam-2 2.11µs ± 1% 2.10µs ± 1% ~ (p=0.151 n=5+5) DecoderFactory_SetDecoderFunc-2 1.92µs ± 1% 1.94µs ± 1% ~ (p=0.151 n=5+5) pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 15.1µs ± 2% 15.3µs ± 4% ~ (p=0.690 n=5+5) Middleware_control-2 3.59µs ± 2% 3.73µs ± 1% +4.08% (p=0.008 n=5+5) name old alloc/op new alloc/op delta pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 2.50kB ± 0% 2.50kB ± 0% ~ (all equal) pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 440B ± 0% 440B ± 0% ~ (all equal) DecoderFunc_Decode-2 1.51kB ± 0% 1.51kB ± 0% ~ (all equal) Decoder_Decode_json-2 12.3kB ± 0% 12.3kB ± 0% ~ (p=0.167 n=5+5) Decoder_Decode_queryObject-2 2.00kB ± 0% 2.00kB ± 0% ~ (all equal) Decoder_Decode_jsonParam-2 720B ± 0% 720B ± 0% ~ (all equal) DecoderFactory_SetDecoderFunc-2 1.02kB ± 0% 1.02kB ± 0% ~ (all equal) pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 1.13kB ± 3% 1.12kB ± 3% ~ (p=0.683 n=5+5) Middleware_control-2 11.2kB ± 0% 11.2kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta pkg:github.com/swaggest/rest/jsonschema goos:linux goarch:amd64 RequestValidator_ValidateRequestData-2 8.00 ± 0% 8.00 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/request goos:linux goarch:amd64 Decoder_Decode-2 4.00 ± 0% 4.00 ± 0% ~ (all equal) DecoderFunc_Decode-2 12.0 ± 0% 12.0 ± 0% ~ (all equal) Decoder_Decode_json-2 169 ± 0% 169 ± 0% ~ (all equal) Decoder_Decode_queryObject-2 36.0 ± 0% 36.0 ± 0% ~ (all equal) Decoder_Decode_jsonParam-2 12.0 ± 0% 12.0 ± 0% ~ (all equal) DecoderFactory_SetDecoderFunc-2 16.0 ± 0% 16.0 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/response/gzip goos:linux goarch:amd64 Middleware-2 11.0 ± 0% 11.0 ± 0% ~ (all equal) Middleware_control-2 9.00 ± 0% 9.00 ± 0% ~ (all equal) ```
github-actions[bot] commented 3 years ago

Examples Benchmark Result

Benchmark diff with base branch ``` name old time/op new time/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 37.8µs ± 3% 39.1µs ± 4% ~ (p=0.095 n=5+5) _directGzipHead-2 37.8µs ± 4% 37.6µs ± 3% ~ (p=1.000 n=5+5) _noDirectGzip-2 166µs ± 3% 169µs ± 2% ~ (p=0.222 n=5+5) _directGzip_decode-2 597µs ± 5% 593µs ± 4% ~ (p=0.690 n=5+5) _noDirectGzip_decode-2 167µs ± 3% 164µs ± 1% ~ (p=0.310 n=5+5) _jsonBody-2 66.1µs ± 4% 67.6µs ± 3% ~ (p=0.151 n=5+5) _jsonBodyValidation-2 74.5µs ± 4% 78.1µs ± 1% +4.83% (p=0.016 n=5+4) _outputHeaders-2 36.7µs ± 1% 39.1µs ± 2% +6.54% (p=0.008 n=5+5) _validation-2 68.9µs ± 3% 73.8µs ± 3% +7.17% (p=0.008 n=5+5) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 42.7µs ± 3% 43.3µs ± 2% ~ (p=0.841 n=5+5) _ok-2 45.1µs ± 4% 45.2µs ± 4% ~ (p=1.000 n=5+5) _invalidBody-2 65.5µs ± 2% 65.3µs ± 2% ~ (p=0.690 n=5+5) name old B:rcvd/op new B:rcvd/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 639 ± 0% 639 ± 0% ~ (all equal) _directGzipHead-2 183 ± 0% 183 ± 0% ~ (all equal) _noDirectGzip-2 1.04k ± 0% 1.04k ± 0% ~ (all equal) _directGzip_decode-2 639 ± 0% 639 ± 0% ~ (all equal) _noDirectGzip_decode-2 1.04k ± 0% 1.04k ± 0% ~ (all equal) _jsonBody-2 208 ± 0% 208 ± 0% ~ (all equal) _jsonBodyValidation-2 194 ± 0% 194 ± 0% ~ (all equal) _outputHeaders-2 155 ± 0% 155 ± 0% ~ (all equal) _validation-2 177 ± 0% 177 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 337 ± 0% 337 ± 0% ~ (all equal) _ok-2 359 ± 0% 359 ± 0% ~ (all equal) _invalidBody-2 435 ± 0% 435 ± 0% ~ (all equal) name old B:sent/op new B:sent/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 103 ± 0% 103 ± 0% ~ (all equal) _directGzipHead-2 104 ± 0% 104 ± 0% ~ (all equal) _noDirectGzip-2 117 ± 0% 117 ± 0% ~ (all equal) _directGzip_decode-2 116 ± 0% 116 ± 0% ~ (all equal) _noDirectGzip_decode-2 130 ± 0% 130 ± 0% ~ (all equal) _jsonBody-2 188 ± 0% 188 ± 0% ~ (all equal) _jsonBodyValidation-2 192 ± 0% 192 ± 0% ~ (all equal) _outputHeaders-2 77.0 ± 0% 77.0 ± 0% ~ (all equal) _validation-2 170 ± 0% 170 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 74.0 ± 0% 74.0 ± 0% ~ (all equal) _ok-2 74.0 ± 0% 74.0 ± 0% ~ (all equal) _invalidBody-2 137 ± 0% 137 ± 0% ~ (all equal) name old rps new rps delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 26.4k ± 3% 25.6k ± 4% ~ (p=0.095 n=5+5) _directGzipHead-2 26.5k ± 4% 26.6k ± 3% ~ (p=1.000 n=5+5) _noDirectGzip-2 6.01k ± 3% 5.93k ± 2% ~ (p=0.222 n=5+5) _directGzip_decode-2 1.68k ± 4% 1.69k ± 4% ~ (p=0.690 n=5+5) _noDirectGzip_decode-2 5.99k ± 3% 6.10k ± 1% ~ (p=0.286 n=5+5) _jsonBody-2 15.1k ± 4% 14.8k ± 3% ~ (p=0.151 n=5+5) _jsonBodyValidation-2 13.4k ± 4% 12.8k ± 1% -4.66% (p=0.016 n=5+4) _outputHeaders-2 27.2k ± 1% 25.6k ± 2% -6.13% (p=0.008 n=5+5) _validation-2 14.5k ± 3% 13.6k ± 3% -6.66% (p=0.008 n=5+5) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 23.4k ± 3% 23.1k ± 2% ~ (p=1.000 n=5+5) _ok-2 22.2k ± 4% 22.1k ± 4% ~ (p=1.000 n=5+5) _invalidBody-2 15.3k ± 2% 15.3k ± 2% ~ (p=0.690 n=5+5) name old alloc/op new alloc/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 3.87kB ± 0% 3.87kB ± 0% ~ (p=0.476 n=5+5) _directGzipHead-2 3.87kB ± 0% 3.87kB ± 0% ~ (p=0.921 n=5+5) _noDirectGzip-2 5.94kB ±15% 6.28kB ±21% ~ (p=0.690 n=5+5) _directGzip_decode-2 403kB ± 0% 403kB ± 0% ~ (p=1.000 n=5+5) _noDirectGzip_decode-2 5.38kB ± 8% 5.32kB ± 2% ~ (p=0.548 n=5+5) _jsonBody-2 11.7kB ± 0% 11.7kB ± 0% +0.03% (p=0.032 n=5+5) _jsonBodyValidation-2 18.2kB ± 0% 18.2kB ± 0% ~ (p=0.730 n=5+5) _outputHeaders-2 3.65kB ± 0% 3.65kB ± 0% ~ (p=0.397 n=4+5) _validation-2 16.2kB ± 0% 16.2kB ± 0% ~ (p=0.421 n=5+5) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 4.82kB ± 0% 4.82kB ± 0% ~ (p=0.286 n=5+5) _ok-2 4.72kB ± 0% 4.73kB ± 0% ~ (p=0.171 n=4+4) _invalidBody-2 8.68kB ± 4% 8.70kB ± 4% ~ (p=0.730 n=5+5) name old allocs/op new allocs/op delta pkg:github.com/swaggest/rest/_examples/advanced goos:linux goarch:amd64 _directGzip-2 40.0 ± 0% 40.0 ± 0% ~ (all equal) _directGzipHead-2 40.0 ± 0% 40.0 ± 0% ~ (all equal) _noDirectGzip-2 47.8 ± 4% 47.8 ± 4% ~ (p=1.000 n=5+5) _directGzip_decode-2 498 ± 0% 498 ± 0% ~ (all equal) _noDirectGzip_decode-2 48.0 ± 0% 48.0 ± 0% ~ (all equal) _jsonBody-2 103 ± 0% 103 ± 0% ~ (all equal) _jsonBodyValidation-2 144 ± 0% 144 ± 0% ~ (all equal) _outputHeaders-2 35.0 ± 0% 35.0 ± 0% ~ (all equal) _validation-2 131 ± 0% 131 ± 0% ~ (all equal) pkg:github.com/swaggest/rest/_examples/task-api/internal/infra/nethttp goos:linux goarch:amd64 _notFoundSrv-2 52.0 ± 0% 52.0 ± 0% ~ (all equal) _ok-2 48.0 ± 0% 48.0 ± 0% ~ (all equal) _invalidBody-2 98.0 ± 0% 98.8 ± 2% ~ (p=0.556 n=4+5) ```