Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions pkg/attribute/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

const (
errUnsupportedAttribute = "unsupported attribute %v"
errUnexpectedType = `unexpected type on attribute %v. expect %s, received %[3]v(%[3]T)`
)

var (
Expand Down Expand Up @@ -270,14 +269,7 @@ func (d Dictionary) Validate(attrs map[string]interface{}) error {
}
}

if desc.typ != unknownType && desc.typ != reflect.TypeOf(v) {
// Allow implicit conversion from int to float to ease typing
if !(desc.typ == floatType && reflect.TypeOf(v) == intType) {
return fmt.Errorf(errUnexpectedType, k, desc.typ, v)
}
}

if desc.checker != nil {
if v != nil && desc.checker != nil {
if err := desc.checker(v); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/attribute/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestDictionaryValidate(t *testing.T) {
a.NoError(tb.Validate(map[string]interface{}{"a": 1}))
a.EqualError(tb.Validate(map[string]interface{}{"a": -1}), "some error")
a.EqualError(tb.Validate(map[string]interface{}{"_a": -1}), fmt.Sprintf(errUnsupportedAttribute, "_a"))
a.EqualError(tb.Validate(map[string]interface{}{"a": 1.0}), fmt.Sprintf(errUnexpectedType, "a", "int", 1.))
a.EqualError(tb.Validate(map[string]interface{}{"a": 1.0}), "attribute a must be of type int, but got float64")
a.NoError(tb.Validate(map[string]interface{}{"b": float32(1.0)}))
a.NoError(tb.Validate(map[string]interface{}{"b": 1}))
}
Expand Down