test(flag): enhance TestCustomFlagGroups to include environment variable support

- Added a test case to verify the behavior of the `TRIVY_FOO` environment variable in the `TestCustomFlagGroups` function.
- Ensured that the flag system correctly retrieves values from both environment variables and custom flags.
- Improved test coverage for the flag handling functionality.
This commit is contained in:
knqyf263
2025-04-14 13:07:36 +04:00
parent 84eb62340e
commit 51cefc4221

View File

@@ -90,7 +90,14 @@ func TestCustomFlagGroups(t *testing.T) {
testOpts := extractTestOptions(t, opts)
assert.Equal(t, "default-value", testOpts.Foo)
// Test
// Test with environment variable
t.Setenv("TRIVY_FOO", "env-value")
opts, err = flags.ToOptions(nil)
require.NoError(t, err)
testOpts = extractTestOptions(t, opts)
assert.Equal(t, "env-value", testOpts.Foo)
// Test with flag
viper.Set(foo.ConfigName, "custom-value")
opts, err = flags.ToOptions(nil)
require.NoError(t, err)