2021-01-20 12:07:40 +00:00
package validator
import (
"testing"
"github.com/stretchr/testify/suite"
2021-08-11 01:04:35 +00:00
"github.com/authelia/authelia/v4/internal/configuration/schema"
2021-01-20 12:07:40 +00:00
)
type Theme struct {
suite . Suite
2022-02-28 03:15:01 +00:00
config * schema . Configuration
validator * schema . StructValidator
2021-01-20 12:07:40 +00:00
}
func ( suite * Theme ) SetupTest ( ) {
suite . validator = schema . NewStructValidator ( )
2022-02-28 03:15:01 +00:00
suite . config = & schema . Configuration {
2021-01-20 12:07:40 +00:00
Theme : "light" ,
}
}
func ( suite * Theme ) TestShouldValidateCompleteConfiguration ( ) {
2022-02-28 03:15:01 +00:00
ValidateTheme ( suite . config , suite . validator )
2021-01-20 12:07:40 +00:00
2022-04-04 07:46:55 +00:00
suite . Assert ( ) . Len ( suite . validator . Warnings ( ) , 0 )
suite . Assert ( ) . Len ( suite . validator . Errors ( ) , 0 )
2021-01-20 12:07:40 +00:00
}
func ( suite * Theme ) TestShouldRaiseErrorWhenInvalidThemeProvided ( ) {
2022-02-28 03:15:01 +00:00
suite . config . Theme = "invalid"
2021-01-20 12:07:40 +00:00
2022-02-28 03:15:01 +00:00
ValidateTheme ( suite . config , suite . validator )
2021-01-20 12:07:40 +00:00
2022-04-04 07:46:55 +00:00
suite . Assert ( ) . Len ( suite . validator . Warnings ( ) , 0 )
2021-01-20 12:07:40 +00:00
suite . Require ( ) . Len ( suite . validator . Errors ( ) , 1 )
2022-02-28 03:15:01 +00: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 12:07:40 +00:00
}
func TestThemes ( t * testing . T ) {
suite . Run ( t , new ( Theme ) )
}