2021-01-20 19:07:40 +07:00
package validator
import (
"testing"
"github.com/stretchr/testify/suite"
2021-08-11 08:04:35 +07:00
"github.com/authelia/authelia/v4/internal/configuration/schema"
2021-01-20 19:07:40 +07:00
)
type Theme struct {
suite . Suite
2022-02-28 10:15:01 +07:00
config * schema . Configuration
validator * schema . StructValidator
2021-01-20 19:07:40 +07:00
}
func ( suite * Theme ) SetupTest ( ) {
suite . validator = schema . NewStructValidator ( )
2022-02-28 10:15:01 +07:00
suite . config = & schema . Configuration {
2021-01-20 19:07:40 +07:00
Theme : "light" ,
}
}
func ( suite * Theme ) TestShouldValidateCompleteConfiguration ( ) {
2022-02-28 10:15:01 +07:00
ValidateTheme ( suite . config , suite . validator )
2021-01-20 19:07:40 +07:00
suite . Assert ( ) . False ( suite . validator . HasWarnings ( ) )
suite . Assert ( ) . False ( suite . validator . HasErrors ( ) )
}
func ( suite * Theme ) TestShouldRaiseErrorWhenInvalidThemeProvided ( ) {
2022-02-28 10:15:01 +07:00
suite . config . Theme = "invalid"
2021-01-20 19:07:40 +07:00
2022-02-28 10:15:01 +07:00
ValidateTheme ( suite . config , suite . validator )
2021-01-20 19:07:40 +07:00
suite . Assert ( ) . False ( suite . validator . HasWarnings ( ) )
suite . Require ( ) . Len ( suite . validator . Errors ( ) , 1 )
2022-02-28 10:15:01 +07:00
suite . Assert ( ) . EqualError ( suite . validator . Errors ( ) [ 0 ] , "option 'theme' must be one of 'light', 'dark', 'grey', 'auto' but it is configured as 'invalid'" )
2021-01-20 19:07:40 +07:00
}
func TestThemes ( t * testing . T ) {
suite . Run ( t , new ( Theme ) )
}