Skip to content

cmds/core/wget: remove testutil#2540

Merged
rminnich merged 7 commits into
u-root:mainfrom
binjip978:wget-testuti
Dec 19, 2022
Merged

cmds/core/wget: remove testutil#2540
rminnich merged 7 commits into
u-root:mainfrom
binjip978:wget-testuti

Conversation

@binjip978
Copy link
Copy Markdown
Contributor

Signed-off-by: Siarhiej Siemianczuk pdp.eleven11@gmail.com

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 27, 2022

Codecov Report

Base: 73.38% // Head: 73.43% // Increases project coverage by +0.05% 🎉

Coverage data is based on head (5bdbadf) compared to base (24c60d4).
Patch coverage: 66.66% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2540      +/-   ##
==========================================
+ Coverage   73.38%   73.43%   +0.05%     
==========================================
  Files         411      411              
  Lines       41746    41751       +5     
==========================================
+ Hits        30635    30661      +26     
+ Misses      11111    11090      -21     
Impacted Files Coverage Δ
pkg/curl/schemes.go 59.50% <0.00%> (ø)
cmds/core/wget/wget.go 68.42% <69.23%> (+68.42%) ⬆️
cmds/core/date/date.go 90.83% <0.00%> (-0.77%) ⬇️
cmds/core/ip/ops_linux.go 79.82% <0.00%> (+0.87%) ⬆️

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

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Copy Markdown
Member

@rminnich rminnich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two questions, nice to see more tests!

Comment thread cmds/core/wget/wget.go Outdated
Comment thread cmds/core/wget/wget.go Outdated
Comment thread cmds/core/wget/wget.go Outdated
@rminnich rminnich added the Awaiting author Waiting for new changes or feedback for author. label Oct 28, 2022
Comment thread cmds/core/wget/wget.go Outdated
Comment thread cmds/core/wget/wget.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
@binjip978 binjip978 force-pushed the wget-testuti branch 2 times, most recently from 496f483 to ec09887 Compare November 4, 2022 05:12
@binjip978 binjip978 requested a review from rminnich November 6, 2022 15:10
Copy link
Copy Markdown
Member

@rminnich rminnich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this new design. You can see my one comment re New() vs new()
Let's see what abrender thinks but I believe we are almost done!

Comment thread cmds/core/wget/wget.go Outdated
Comment thread cmds/core/wget/wget.go Outdated
Comment thread cmds/core/wget/wget.go
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
@binjip978 binjip978 force-pushed the wget-testuti branch 2 times, most recently from 95b8156 to 49bd7cb Compare November 9, 2022 12:19
@binjip978 binjip978 requested review from abrender and rminnich and removed request for rminnich November 9, 2022 13:14
Copy link
Copy Markdown
Contributor

@abrender abrender left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for continuing to work on this - it is appreciated!

Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget.go
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread pkg/curl/schemes.go
@binjip978
Copy link
Copy Markdown
Contributor Author

looks like we can't guarantee EOF wget_test.go:143: expected: EOF, got: failed to download http://localhost:33527/200: encountered error Get "http://localhost:33527/200": http: server closed

pervious test just check for non zero, but this seems flaky on CI.

Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
@binjip978
Copy link
Copy Markdown
Contributor Author

looks like we can't guarantee EOF wget_test.go:143: expected: EOF, got: failed to download http://localhost:33527/200: encountered error Get "http://localhost:33527/200": http: server closed

pervious test just check for non zero, but this seems flaky on CI.

Can't made it work. It may return at least 3 different errors and one of the is even internal errServerClosedIdle = errors.New("http: server closed idle connection"). So I diced to remove this test, seems like it's not testing anything in wget command, and probably does not do anything pkg/curl either. Error is returned in httpFetch functions in scheme.go in line 393 resp, err := c.Do(req).

Or I can remove errors.Is and check for error code 1 or 0.

@abrender
Copy link
Copy Markdown
Contributor

abrender commented Nov 15, 2022

looks like we can't guarantee EOF wget_test.go:143: expected: EOF, got: failed to download http://localhost:33527/200: encountered error Get "http://localhost:33527/200": http: server closed
pervious test just check for non zero, but this seems flaky on CI.

Can't made it work. It may return at least 3 different errors and one of the is even internal errServerClosedIdle = errors.New("http: server closed idle connection"). So I diced to remove this test, seems like it's not testing anything in wget command, and probably does not do anything pkg/curl either. Error is returned in httpFetch functions in scheme.go in line 393 resp, err := c.Do(req).

Or I can remove errors.Is and check for error code 1 or 0.

Perhaps cmpopts.EquateErrors and AnyError can help here?

import(
    "github.com/google/go-cmp/cmp"
    "github.com/google/go-cmp/cmp/cmpopts"
)

// Update test case to have `err: cmpopts.AnyError` instead of io.EOF

if !cmp.Equal(tt.err, err, cmpopts.EquateErrors()) {
  t.Errorf("Got error=%v, expected=%v", err, tt.err)
}
if (err != nil || tt.err != nil ) {
   return
}
...



@binjip978
Copy link
Copy Markdown
Contributor Author

looks like we can't guarantee EOF wget_test.go:143: expected: EOF, got: failed to download http://localhost:33527/200: encountered error Get "http://localhost:33527/200": http: server closed
pervious test just check for non zero, but this seems flaky on CI.

Can't made it work. It may return at least 3 different errors and one of the is even internal errServerClosedIdle = errors.New("http: server closed idle connection"). So I diced to remove this test, seems like it's not testing anything in wget command, and probably does not do anything pkg/curl either. Error is returned in httpFetch functions in scheme.go in line 393 resp, err := c.Do(req).
Or I can remove errors.Is and check for error code 1 or 0.

Perhaps cmpopts.EquateErrors and AnyError can help here?

import(
    "github.com/google/go-cmp/cmp"
    "github.com/google/go-cmp/cmp/cmpopts"
)

// Update test case to have `err: cmpopts.AnyError` instead of io.EOF

if !cmp.Equal(tt.err, err, cmpopts.EquateErrors()) {
  t.Errorf("Got error=%v, expected=%v", err, tt.err)
}
if (err != nil || tt.err != nil ) {
   return
}
...

This will work, but I would prefer to just separate this test case and do simple if err != nil { t.Error() } and don't bring any additional dependencies. This is better aligned with go values "a little copying is better than a little dependency".

The problem with this that I don't fully understand what the purpose of this test case. We already covered error case for curl command with 4xx and 5xx test cases. What kind of http related error we got there it's not a wget command problem, it's maybe a problem of curl lib, but error comes from http client do function.
But I probably missing something.

@abrender
Copy link
Copy Markdown
Contributor

looks like we can't guarantee EOF wget_test.go:143: expected: EOF, got: failed to download http://localhost:33527/200: encountered error Get "http://localhost:33527/200": http: server closed
pervious test just check for non zero, but this seems flaky on CI.

Can't made it work. It may return at least 3 different errors and one of the is even internal errServerClosedIdle = errors.New("http: server closed idle connection"). So I diced to remove this test, seems like it's not testing anything in wget command, and probably does not do anything pkg/curl either. Error is returned in httpFetch functions in scheme.go in line 393 resp, err := c.Do(req).
Or I can remove errors.Is and check for error code 1 or 0.

Perhaps cmpopts.EquateErrors and AnyError can help here?

import(
    "github.com/google/go-cmp/cmp"
    "github.com/google/go-cmp/cmp/cmpopts"
)

// Update test case to have `err: cmpopts.AnyError` instead of io.EOF

if !cmp.Equal(tt.err, err, cmpopts.EquateErrors()) {
  t.Errorf("Got error=%v, expected=%v", err, tt.err)
}
if (err != nil || tt.err != nil ) {
   return
}
...

This will work, but I would prefer to just separate this test case and do simple if err != nil { t.Error() } and don't bring any additional dependencies. This is better aligned with go values "a little copying is better than a little dependency".

The problem with this that I don't fully understand what the purpose of this test case. We already covered error case for curl command with 4xx and 5xx test cases. What kind of http related error we got there it's not a wget command problem, it's maybe a problem of curl lib, but error comes from http client do function. But I probably missing something.

Sure, a separate test for err != nil sounds fine to me :) I was just throwing out a solution if you wanted to keep it in a single test.

As for what it's testing - I'm not the original author, but I assume there's a reasonable assumption that error handling for HTTP status codes is different than error handling for errors unrelated to HTTP status codes (like network errors).

add none nil error to HTTPClientCodeError if error code is not 200 to
make errors.Is work

Signed-off-by: Siarhiej Siemianczuk <pdp.eleven11@gmail.com>
Signed-off-by: Siarhiej Siemianczuk <pdp.eleven11@gmail.com>
Signed-off-by: Siarhiej Siemianczuk <pdp.eleven11@gmail.com>
under -race wget can return three different errors and this made
errors.Is problematic to use

Signed-off-by: Siarhiej Siemianczuk <pdp.eleven11@gmail.com>
Signed-off-by: Siarhiej Siemianczuk <pdp.eleven11@gmail.com>
Comment thread cmds/core/wget/wget_test.go Outdated
Comment thread cmds/core/wget/wget_test.go Outdated
Signed-off-by: Siarhiej Siemianczuk <pdp.eleven11@gmail.com>
@abrender
Copy link
Copy Markdown
Contributor

Looks good to me! Thank you so much for your patience.

I'll await @rminnich to resolve his open comment threads

@binjip978 binjip978 marked this pull request as draft November 22, 2022 06:39
@binjip978 binjip978 marked this pull request as ready for review November 22, 2022 06:39
@binjip978
Copy link
Copy Markdown
Contributor Author

Looks good to me! Thank you so much for your patience.

I'll await @rminnich to resolve his open comment threads

Thanks for feedback, appreciate it :) Learned a bit about current Fatal behaviour.

@binjip978 binjip978 requested a review from rminnich December 18, 2022 19:17
@binjip978
Copy link
Copy Markdown
Contributor Author

Sorry @rminnich but I can't change labels, so pinging you via mention :)

Copy link
Copy Markdown
Member

@rminnich rminnich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a substantial improvement. Thanks for your patience.

Comment thread cmds/core/wget/wget.go
@rminnich rminnich merged commit bac9c58 into u-root:main Dec 19, 2022
@binjip978 binjip978 deleted the wget-testuti branch December 19, 2022 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Awaiting author Waiting for new changes or feedback for author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants