forked from go-openapi/validate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formats_test.go
40 lines (31 loc) · 868 Bytes
/
formats_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package validate
import (
"reflect"
"testing"
"github.com/go-openapi/spec"
"github.com/go-openapi/strfmt"
"github.com/stretchr/testify/assert"
)
// Validator for string formats
func TestFormatValidator_EdgeCases(t *testing.T) {
// Apply
v := formatValidator{
KnownFormats: strfmt.Default,
}
// formatValidator applies to: Items, Parameter,Schema
p := spec.Parameter{}
p.Typed("string", "email")
s := spec.Schema{}
s.Typed("string", "uuid")
i := spec.Items{}
i.Typed("string", "datetime")
sources := []interface{}{&p, &s, &i}
for _, source := range sources {
// Default formats for strings
assert.True(t, v.Applies(source, reflect.String))
// Do not apply for number formats
assert.False(t, v.Applies(source, reflect.Int))
}
assert.False(t, v.Applies("A string", reflect.String))
assert.False(t, v.Applies(nil, reflect.String))
}