-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: skip networked tests if no connection #661
Conversation
Hey @caarlos0 or @aymanbagabas I may need some help getting CI fixed here. It seems to be detecting |
I looked into this, but not sure why its failing.. FWIW we have the url tests that are also skipped due to weird network stuff... maybe worth just removing them |
glow_test.go
Outdated
// Check for network issues. | ||
if errors.As(err, &urlErr) { | ||
t.Logf("Error during execution (args: %s):\n%v", v, err) | ||
t.Skip("Test uses network. Are you connected to the Internet?") | ||
} else { | ||
t.Errorf("Error during execution (args: %s): %T %v", v, err, err) | ||
} | ||
|
||
if buf.Len() == 0 { | ||
t.Errorf("Output buffer should not be empty (args: %s)", v) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be easier to read
// Check for network issues. | |
if errors.As(err, &urlErr) { | |
t.Logf("Error during execution (args: %s):\n%v", v, err) | |
t.Skip("Test uses network. Are you connected to the Internet?") | |
} else { | |
t.Errorf("Error during execution (args: %s): %T %v", v, err, err) | |
} | |
if buf.Len() == 0 { | |
t.Errorf("Output buffer should not be empty (args: %s)", v) | |
} | |
// Check for network issues. | |
if errors.As(err, &urlErr) { | |
t.Logf("Error during execution (args: %s):\n%v", v, err) | |
t.Skip("Test uses network. Are you connected to the Internet?") | |
return | |
} | |
t.Errorf("Error during execution (args: %s): %T %v", v, err, err) | |
if buf.Len() == 0 { | |
t.Errorf("Output buffer should not be empty (args: %s)", v) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I'm just debugging github actions right now, will be undoing these commits once I figure out what's going on 😅
glow_test.go
Outdated
@@ -16,13 +18,21 @@ func TestGlowSources(t *testing.T) { | |||
|
|||
for _, v := range tt { | |||
t.Run(v, func(t *testing.T) { | |||
var urlErr *net.DNSError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move the variable definition aside the errors.As
main.go
Outdated
// a GitHub or GitLab URL (even without the protocol): | ||
var dnsErr *net.DNSError | ||
src, err := readmeURL(arg) | ||
if src != nil && err == nil { | ||
// if there's an error, try next methods... | ||
return src, nil | ||
} else if err != nil && errors.As(err, &dnsErr) { | ||
// fail if there's a network error. | ||
return src, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code could be clearer
// a GitHub or GitLab URL (even without the protocol): | |
var dnsErr *net.DNSError | |
src, err := readmeURL(arg) | |
if src != nil && err == nil { | |
// if there's an error, try next methods... | |
return src, nil | |
} else if err != nil && errors.As(err, &dnsErr) { | |
// fail if there's a network error. | |
return src, err | |
// a GitHub or GitLab URL (even without the protocol): | |
src, err := readmeURL(arg) | |
if src != nil && err == nil { | |
// if there's an error, try next methods... | |
return src, nil | |
} | |
var dnsErr *net.DNSError | |
if errors.As(err, &dnsErr) { | |
// fail if there's a network error. | |
return src, err |
- The
else
is not needed as you usereturn
in theif
- no need to check
err != nil && errors.As(err
, see https://cs.opensource.google/go/go/+/refs/tags/go1.23.4:src/errors/wrap.go;l=97-100
main.go
Outdated
@@ -77,11 +77,12 @@ func sourceFromArg(arg string) (*source, error) { | |||
|
|||
// a GitHub or GitLab URL (even without the protocol): | |||
var dnsErr *net.DNSError | |||
var opErr *net.OpError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you are testing net.OpError
then you shouldn't test net.DNSError too
Here are some explanations:
https://stackoverflow.com/questions/69568234/how-do-i-work-out-what-type-of-error-my-error-is-in-go
https://haisum.github.io/2021/08/14/2021-golang-http-errors/
maybe url.Error could be enough for you
573b982
to
3e612da
Compare
ci is failing because it's getting a forbidden response from the I vote to just delete |
after all that I just deleted the networked test 😂