-
Notifications
You must be signed in to change notification settings - Fork 0
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 config
#71
Test config
#71
Conversation
f232daa
to
2d3bad2
Compare
err := ParseFlags(nil) | ||
require.ErrorIs(t, err, ErrInvalidArgument) | ||
}) | ||
} |
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.
There are no tests for a parser.Parse()
error. However, this may require some code changes as otherwise one has to recover from os.Exit()
.
icinga-go-library/config/config.go
Lines 70 to 78 in d8bd22a
if _, err := parser.Parse(); err != nil { | |
var flagErr *flags.Error | |
if errors.As(err, &flagErr) && flagErr.Type == flags.ErrHelp { | |
fmt.Fprintln(os.Stdout, flagErr) | |
os.Exit(0) | |
} | |
return errors.Wrap(err, "can't parse CLI flags") | |
} |
However, covering this is not completely necessary, imo.
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.
Recover from os.Exit()
is impossible using the stdlib, at least to my knowledge. But we could test that using a subprocess. I'll give it a try.
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.
A simpler approach would have been to refactor ParseFlags(v any)
to parseFlags(v any, exitOnHelp bool)
and let ParseFlags
call parseFlags(v, true)
, allowing to test parseFlags(…, false)
. But I really appreciate the effort.
d7eae21
to
b93c892
Compare
@oxzi I have adjusted the code based on your preview. Please take another look at it. I have already moved code unfortunately, so the comments are no longer aligned correctly. |
This PR introduces tests for the
ParseFlags()
,FromYAMLFile()
andTLS.MakeConfig()
functions:ParseFlags
FromYAMLFile
TLS.MakeConfig()
Basic Configuration
nil
when TLS is disabled.InsecureSkipVerify
is set totrue
when specified.x509 Certificate Handling