2021-06-01 04:09:50 +00:00
package validator
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2021-08-11 01:04:35 +00:00
"github.com/authelia/authelia/v4/internal/configuration/schema"
2021-06-01 04:09:50 +00:00
)
func TestShouldSetDefaultLoggingValues ( t * testing . T ) {
config := & schema . Configuration { }
validator := schema . NewStructValidator ( )
2022-02-28 03:15:01 +00:00
ValidateLog ( config , validator )
2021-06-01 04:09:50 +00:00
assert . Len ( t , validator . Warnings ( ) , 0 )
assert . Len ( t , validator . Errors ( ) , 0 )
2021-08-03 09:55:21 +00:00
require . NotNil ( t , config . Log . KeepStdout )
2021-06-01 04:09:50 +00:00
2021-08-03 09:55:21 +00:00
assert . Equal ( t , "info" , config . Log . Level )
assert . Equal ( t , "text" , config . Log . Format )
assert . Equal ( t , "" , config . Log . FilePath )
2021-06-01 04:09:50 +00:00
}
func TestShouldRaiseErrorOnInvalidLoggingLevel ( t * testing . T ) {
config := & schema . Configuration {
2021-08-03 09:55:21 +00:00
Log : schema . LogConfiguration {
2021-06-01 04:09:50 +00:00
Level : "TRACE" ,
} ,
}
validator := schema . NewStructValidator ( )
2022-02-28 03:15:01 +00:00
ValidateLog ( config , validator )
2021-06-01 04:09:50 +00:00
assert . Len ( t , validator . Warnings ( ) , 0 )
require . Len ( t , validator . Errors ( ) , 1 )
2023-04-13 10:58:18 +00:00
assert . EqualError ( t , validator . Errors ( ) [ 0 ] , "log: option 'level' must be one of 'trace', 'debug', 'info', 'warn', or 'error' but it's configured as 'TRACE'" )
2021-06-01 04:09:50 +00:00
}