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
|
|
|
|
configuration *schema.Configuration
|
|
|
|
validator *schema.StructValidator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Theme) SetupTest() {
|
|
|
|
suite.validator = schema.NewStructValidator()
|
|
|
|
suite.configuration = &schema.Configuration{
|
|
|
|
Theme: "light",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Theme) TestShouldValidateCompleteConfiguration() {
|
|
|
|
ValidateTheme(suite.configuration, suite.validator)
|
|
|
|
|
|
|
|
suite.Assert().False(suite.validator.HasWarnings())
|
|
|
|
suite.Assert().False(suite.validator.HasErrors())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Theme) TestShouldRaiseErrorWhenInvalidThemeProvided() {
|
|
|
|
suite.configuration.Theme = "invalid"
|
|
|
|
|
|
|
|
ValidateTheme(suite.configuration, suite.validator)
|
|
|
|
|
|
|
|
suite.Assert().False(suite.validator.HasWarnings())
|
|
|
|
suite.Require().Len(suite.validator.Errors(), 1)
|
|
|
|
|
2021-06-17 13:42:03 +07:00
|
|
|
suite.Assert().EqualError(suite.validator.Errors()[0], "Theme: invalid is not valid, valid themes are: \"light\", \"dark\", \"grey\" or \"auto\"")
|
2021-01-20 19:07:40 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestThemes(t *testing.T) {
|
|
|
|
suite.Run(t, new(Theme))
|
|
|
|
}
|