add test for max int64 validator
This commit is contained in:
37
internal/block/int64_component/validators/max_test.go
Normal file
37
internal/block/int64_component/validators/max_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package int64_component_validators
|
||||
|
||||
import (
|
||||
"blocky/internal/block/int64_component"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMax(t *testing.T) {
|
||||
cfg := &int64_component.Int64ComponentConfig{}
|
||||
Max(10)(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 int64
|
||||
wantErr bool
|
||||
}{
|
||||
|
||||
{"below value", 5, false},
|
||||
{"equal to value", 10, false},
|
||||
{"above value", 15, true},
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user