chore: added test case for log_format

This commit is contained in:
Damandeep Singh
2025-02-27 21:23:51 +05:30
parent fd2757a8d4
commit 5ce7ea7aa0
3 changed files with 32 additions and 4 deletions

View File

@@ -123,7 +123,8 @@ func ConfigureServices(
return err
}
logrus.SetLevel(level)
switch serverConfig.LogFormat() {
format := strings.ToLower(fmt.Sprintf("%v", serverConfig.LogFormat()))
switch format {
case "json":
logrus.SetFormatter(&logrus.JSONFormatter{})
default:

View File

@@ -281,9 +281,10 @@ func ValidateConfig(config ServerConfig) error {
if config.LogLevel().String() == "unknown" {
return fmt.Errorf("loglevel is invalid: %v\n", string(config.LogLevel()))
}
if config.LogFormat() != "text" && config.LogFormat() != "json" {
return fmt.Errorf("logformat is invalid: %v\n", config.LogFormat())
}
if strings.ToLower(fmt.Sprintf("%v", config.LogFormat())) != "text" &&
strings.ToLower(fmt.Sprintf("%v", config.LogFormat())) != "json" {
return fmt.Errorf("logformat is invalid: %v\n", config.LogFormat())
}
if config.RequireSecureTransport() && config.TLSCert() == "" && config.TLSKey() == "" {
return fmt.Errorf("require_secure_transport can only be `true` when a tls_key and tls_cert are provided.")
}

View File

@@ -145,6 +145,32 @@ EOF
dolt sql -q "show databases;"
stop_sql_server
}
@test "sql-server: logformats are case insensitive" {
# assert that logformat on command line is not case sensitive
cd repo1
PORT=$( definePORT )
dolt sql-server --logformat jSon --port=$PORT --socket "dolt.$PORT.sock" > log.txt 2>&1 &
SERVER_PID=$!
wait_for_connection $PORT 8500
dolt sql -q "show databases;"
stop_sql_server
# assert that logformat in yaml config is not case sensitive
cat >config.yml <<EOF
log_format: teXt
behavior:
disable_client_multi_statements: true
listener:
host: "0.0.0.0"
port: $PORT
EOF
dolt sql-server --config ./config.yml --socket "dolt.$PORT.sock" &
SERVER_PID=$!
wait_for_connection $PORT 8500
dolt sql -q "show databases;"
stop_sql_server
}
@test "sql-server: server assumes existing user" {
cd repo1