open-vault/command/log_flags_test.go
Peter Wilson 33e6a3a87c
VAULT-9900: Log rotation for 'agent' and 'server' commands (#18031)
* Work to unify log-file for agent/server and add rotation
* Updates to rotation code, tried to centralise the log config setup
* logging + tests
* Move LogFile to ShareConfig in test
* Docs
2022-11-29 14:07:04 +00:00

76 lines
1.5 KiB
Go

package command
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLogFlags_ValuesProvider(t *testing.T) {
cases := map[string]struct {
flagKey string
envVarKey string
current string
fallback string
want string
}{
"only-fallback": {
flagKey: "invalid",
envVarKey: "invalid",
current: "",
fallback: "foo",
want: "foo",
},
"only-config": {
flagKey: "invalid",
envVarKey: "invalid",
current: "bar",
fallback: "",
want: "bar",
},
"flag-missing": {
flagKey: "invalid",
envVarKey: "valid-env-var",
current: "my-config-value1",
fallback: "",
want: "envVarValue",
},
"envVar-missing": {
flagKey: "valid-flag",
envVarKey: "invalid",
current: "my-config-value1",
fallback: "",
want: "flagValue",
},
"all-present": {
flagKey: "valid-flag",
envVarKey: "valid-env-var",
current: "my-config-value1",
fallback: "foo",
want: "flagValue",
},
}
// Sneaky little fake provider
fakeProvider := func(key string) (string, bool) {
switch key {
case "valid-flag":
return "flagValue", true
case "valid-env-var":
return "envVarValue", true
}
return "", false
}
vp := valuesProvider{
flagProvider: fakeProvider,
envVarProvider: fakeProvider,
}
for _, tc := range cases {
got := vp.getAggregatedConfigValue(tc.flagKey, tc.envVarKey, tc.current, tc.fallback)
assert.Equal(t, tc.want, got)
}
}