🔧 Add support for logLevel in any case (#231)

This commit is contained in:
mathieuHa
2025-04-06 10:41:16 +02:00
committed by GitHub
parent 7f99266f99
commit 78869ecf77
4 changed files with 15 additions and 5 deletions
+2 -2
View File
@@ -268,8 +268,8 @@ func ValidateParams(config *Config) error {
}
// Check logging configuration
if !contains([]string{LogERROR, LogDEBUG, LogINFO}, config.LogLevel) {
// to upper allow of anycase of log level
if !contains([]string{LogERROR, LogDEBUG, LogINFO}, strings.ToUpper(config.LogLevel)) {
return fmt.Errorf("LogLevel should be one of (%s,%s,%s)", LogDEBUG, LogINFO, LogERROR)
}
if config.LogFilePath != "" {
+11 -2
View File
@@ -85,8 +85,14 @@ func Test_ValidateParams(t *testing.T) {
cfg6 := getMinimalConfig()
cfg6.CrowdsecLapiScheme = HTTPS
cfg6.CrowdsecLapiTLSInsecureVerify = true
cfg7 := getMinimalConfig()
cfg7.CrowdsecLapiScheme = HTTPS
cfg8 := getMinimalConfig()
cfg8.CrowdsecLapiScheme = HTTPS
cfg8.LogLevel = LogINFO
cfg9 := getMinimalConfig()
cfg9.LogLevel = "info"
cfg10 := getMinimalConfig()
cfg10.LogLevel = "Warning"
type args struct {
config *Config
}
@@ -104,7 +110,10 @@ func Test_ValidateParams(t *testing.T) {
{name: "Not validate a bad clients ips", args: args{config: cfg5}, wantErr: true},
// HTTPS enabled
{name: "Validate https config with insecure verify", args: args{config: cfg6}, wantErr: false},
{name: "Not validate https without cert authority", args: args{config: cfg8}, wantErr: true},
{name: "Not validate https without cert authority", args: args{config: cfg7}, wantErr: true},
{name: "Valid log level uppercase INFO", args: args{config: cfg8}, wantErr: false},
{name: "Valid log level lowercase info", args: args{config: cfg9}, wantErr: false},
{name: "Invalid log level Warning", args: args{config: cfg10}, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {