benchttp / engine

Benchttp library in Go to run performance tests on HTTP endpoints.
Other
4 stars 1 forks source link

feat: package benchttptest #62

Closed GregoryAlbouy closed 1 year ago

GregoryAlbouy commented 1 year ago

Description

Package benchttptest provides utilities for benchttp testing.

It exposes comparison utilities to be used by benchttp consumers in their tests: configparse/configio, benchttp/cli.configflag, and any source that needs to ensure it creates or retrieves an expected benchttp.Runner.

Currently exposed functions:

// AssertEqualRunners fails t and shows a diff if a and b are not equal,
// as determined by RunnerCmpOptions.
func AssertEqualRunners(t *testing.T, x, y benchttp.Runner) {}

// EqualRunners returns true if x and y are equal, as determined by
// RunnerCmpOptions.
func EqualRunners(x, y benchttp.Runner) bool {}

// DiffRunner returns a string showing the diff between x and y,
// as determined by RunnerCmpOptions.
func DiffRunner(x, y benchttp.Runner) string {}

It uses go-cmp internally, which allows to fine-tune equality checks contrary to reflect.DeepEqual. However it has some severe rules regarding immutability and I haven't managed to tweak it around Request.Body, as it cannot be read without mutation. As a work-around we simply compare the body separately (and restore it afterwards).

Changes

No changes to the existing in this PR. However it makes tests much simpler in the following PRs:

Notes

codecov-commenter commented 1 year ago

Codecov Report

Merging #62 (6c67087) into main (5a25fcb) will decrease coverage by 0.15%. The diff coverage is 71.73%.

:exclamation: Current head 6c67087 differs from pull request most recent head 243547c. Consider uploading reports for the commit 243547c to get more accurate results

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main      #62      +/-   ##
==========================================
- Coverage   74.40%   74.26%   -0.15%     
==========================================
  Files          25       26       +1     
  Lines         801      847      +46     
==========================================
+ Hits          596      629      +33     
- Misses        181      191      +10     
- Partials       24       27       +3     
Flag Coverage Δ
unittests 74.26% <71.73%> (-0.15%) :arrow_down:

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

Impacted Files Coverage Δ
benchttptest/compare.go 71.73% <71.73%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.