go-resty / resty

Simple HTTP and REST client library for Go
MIT License
9.89k stars 696 forks source link

fix TestClientOnResponseError parallel tests #710

Closed SVilgelm closed 11 months ago

SVilgelm commented 11 months ago

In case of using t.Parallel() inside a for loop, the loop variables must be copied, otherwise only the last test will be executed.

    for _, test := range tests {
        t.Run(test.name, func(t *testing.T) {
            t.Parallel()

changed to

    for _, test := range tests {
        test := test
        t.Run(test.name, func(t *testing.T) {
            t.Parallel()

also the AuthServer must be created within the test, otherwise some tests fail.

t.Log(test.Name) can be used to verify the issue:

    for _, test := range tests {
        t.Run(test.name, func(t *testing.T) {
            t.Parallel()
            t.Log("Test name:", test.name)
Screenshot 2023-09-24 at 8 22 42 PM
codecov[bot] commented 11 months ago

Codecov Report

Patch coverage has no change and project coverage change: +0.55% :tada:

Comparison is base (1ae2aac) 95.65% compared to head (b6a0e29) 96.21%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #710 +/- ## ========================================== + Coverage 95.65% 96.21% +0.55% ========================================== Files 12 12 Lines 1612 1612 ========================================== + Hits 1542 1551 +9 + Misses 42 38 -4 + Partials 28 23 -5 ``` [see 2 files with indirect coverage changes](https://app.codecov.io/gh/go-resty/resty/pull/710/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-resty)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

SVilgelm commented 11 months ago

I saw this issue so many times :)

jeevatkm commented 11 months ago

It would be helpful if go test throws some warning or error if it detects this case.