Added ErrInvalidDataType value for errors checking

This commit is contained in:
Maxim Lebedev 2017-12-13 15:06:44 +05:00
parent 2aa4b849d5
commit 9789b5403f
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
2 changed files with 6 additions and 2 deletions

View File

@ -31,6 +31,10 @@ type (
}
)
// ErrInvalidDataType is returned when ContentFormat function are passed a data argument of invalid
// type.
var ErrInvalidDataType = errors.New("invalid data type")
// ContentFormat transforms data to a DOM-based format to represent the content of the page.
func ContentFormat(data interface{}) ([]Node, error) {
var doc html.Node
@ -54,7 +58,7 @@ func ContentFormat(data interface{}) ([]Node, error) {
}
doc = *dom
default:
return nil, errors.New("invalid data type, use []byte or string")
return nil, ErrInvalidDataType
}
var content []Node

View File

@ -11,7 +11,7 @@ const (
var invalidAccount = &Account{}
func TestInvalidContentFormat(t *testing.T) {
if _, err := ContentFormat(invalidContent); err == nil {
if _, err := ContentFormat(invalidContent); err != ErrInvalidDataType {
t.Error()
}
}