-
Notifications
You must be signed in to change notification settings - Fork 43
test: add test for options env #161
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
Conversation
options_test.go
Outdated
t.Setenv("SETUP_SCRIPT", "setup.sh") | ||
t.Setenv("CACHE_TTL_DAYS", "7") | ||
t.Setenv("IGNORE_PATHS", "/var,/tmp") | ||
t.Setenv("SKIP_REBUILD", "true") |
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 previous code was using https://pkg.go.dev/strconv#ParseBool, but I'm not sure what the new code is using so we might need to test 1
/0
/true
/false
(and the latter two's capitalised equivalents).
Co-authored-by: Danny Kopping <[email protected]>
The t.Run("string", func(t *testing.T) {
var o envbuilder.Options
set := o.CLI()
err := set.ParseEnv([]serpent.EnvVar{
{"SETUP_SCRIPT", "setup.sh"},
{"INIT_COMMAND", "sleep infinity"},
})
require.NoError(t, err)
require.Equal(t, o.SetupScript, "setup.sh")
require.Equal(t, o.InitCommand, "sleep infinity")
}) If we do this, we can also just merge all the tests. But one thing that feels off here is that we are only testing the happy paths, which makes this test feel weak in general. We could comment this is just a sanity check to make sure we don't change env vars without documenting it to prevent any breaking changes. In that case, I think merging the tests and doing it the method above would be a bit cleaner. // TestEnvOptionParsing prevents breaking changes to the environment variables.
func TestEnvOptionParsing(t *testing.T) {
t.Parallel()
var o envbuilder.Options
set := o.CLI()
err := set.ParseEnv([]serpent.EnvVar{
{"SETUP_SCRIPT", "setup.sh"},
{"INIT_COMMAND", "sleep infinity"},
// ... Add the rest
{"CACHE_TTL_DAYS", "7"},
})
require.NoError(t, err)
require.Equal(t, o.SetupScript, "setup.sh")
require.Equal(t, o.InitCommand, "sleep infinity")
// ... Add the rest
require.Equal(t, o.CacheTTLDays, int64(7))
} |
@Emyrk I think it makes sense. Since it is a straightforward test I don't see how to test "unhappy" paths, how would you do that in this scenario? |
I don't think it is worth it to test unhappy paths, it does feel excessive. Just trying to determine what value this test brings. We do not add any validation I can see to the options either, so unhappy paths like negative numbers, or urls are not caught at this layer. |
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.
Almost there, thanks @BrunoQuaresma 👍
Co-authored-by: Danny Kopping <[email protected]>
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 looks fine to me. I think we should port a more rigorous test like this to the serpent package.
Side note, do we not have a linter on this project?
Good work @BrunoQuaresma! Thanks for being patient with the review. |
After some thinking, I concluded that we don't need to test all the env vars but how those values are parsed, but let me know if you think we should test all the env variables.
Closes #157