feat(ui): Implement endpoints[].ui.hide-conditions

This commit is contained in:
TwiN
2024-04-18 20:57:07 -04:00
parent 7efe7429dd
commit e0ab35e86a
5 changed files with 80 additions and 0 deletions

53
core/ui/ui_test.go Normal file
View File

@ -0,0 +1,53 @@
package ui
import (
"errors"
"testing"
)
func TestValidateAndSetDefaults(t *testing.T) {
tests := []struct {
name string
config *Config
wantErr error
}{
{
name: "with-valid-config",
config: &Config{
Badge: &Badge{
ResponseTime: &ResponseTime{Thresholds: []int{50, 200, 300, 500, 750}},
},
},
wantErr: nil,
},
{
name: "with-invalid-threshold-length",
config: &Config{
Badge: &Badge{
ResponseTime: &ResponseTime{Thresholds: []int{50, 200, 300, 500}},
},
},
wantErr: ErrInvalidBadgeResponseTimeConfig,
},
{
name: "with-invalid-thresholds-order",
config: &Config{
Badge: &Badge{ResponseTime: &ResponseTime{Thresholds: []int{50, 200, 500, 300, 750}}},
},
wantErr: ErrInvalidBadgeResponseTimeConfig,
},
{
name: "with-no-badge-configured", // should give default badge cfg
config: &Config{},
wantErr: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.config.ValidateAndSetDefaults(); !errors.Is(err, tt.wantErr) {
t.Errorf("Expected error %v, got %v", tt.wantErr, err)
}
})
}
}