Skip to content

Commit

Permalink
chore: added test case for log_format
Browse files Browse the repository at this point in the history
  • Loading branch information
damanV5 committed Feb 27, 2025
1 parent fd2757a commit 5ce7ea7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion go/cmd/dolt/commands/sqlserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions go/libraries/doltcore/servercfg/serverconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
26 changes: 26 additions & 0 deletions integration-tests/bats/sql-server.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ce7ea7

Please sign in to comment.