Files
blocky/internal/block/validation/required_test.go

36 lines
648 B
Go

package validation
import (
"testing"
)
func TestRequired(t *testing.T) {
cfg := &ComponentConfig{}
Required()(cfg)
if len(cfg.Validators) != 1 {
t.Fatalf("expect 1 validator, got %d", len(cfg.Validators))
}
validate := cfg.Validators[0]
tests := []struct {
name string
value any
wantErr bool
}{
{"nil value", nil, true},
{"empty string", "", true},
{"non-empty string", "hello", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validate(tt.value)
if (err != nil) != tt.wantErr {
t.Errorf("validate(%v) error = %v, wantErr %v", tt.value, err, tt.wantErr)
}
})
}
}