validation: Return "invalid RFC3339 timestamp" in ValidateRFC3339TimeString
This commit is contained in:
parent
ea64b24cd9
commit
994a78dbc7
|
@ -216,7 +216,7 @@ func ValidateRegexp(v interface{}, k string) (ws []string, errors []error) {
|
||||||
// as time.RFC3339 format
|
// as time.RFC3339 format
|
||||||
func ValidateRFC3339TimeString(v interface{}, k string) (ws []string, errors []error) {
|
func ValidateRFC3339TimeString(v interface{}, k string) (ws []string, errors []error) {
|
||||||
if _, err := time.Parse(time.RFC3339, v.(string)); err != nil {
|
if _, err := time.Parse(time.RFC3339, v.(string)); err != nil {
|
||||||
errors = append(errors, fmt.Errorf("%q: %s", k, err))
|
errors = append(errors, fmt.Errorf("%q: invalid RFC3339 timestamp", k))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,37 +161,37 @@ func TestValidateRFC3339TimeString(t *testing.T) {
|
||||||
{
|
{
|
||||||
val: "03/01/2018",
|
val: "03/01/2018",
|
||||||
f: ValidateRFC3339TimeString,
|
f: ValidateRFC3339TimeString,
|
||||||
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`cannot parse "1/2018" as "2006"`)),
|
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`invalid RFC3339 timestamp`)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
val: "03-01-2018",
|
val: "03-01-2018",
|
||||||
f: ValidateRFC3339TimeString,
|
f: ValidateRFC3339TimeString,
|
||||||
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`cannot parse "1-2018" as "2006"`)),
|
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`invalid RFC3339 timestamp`)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
val: "2018-03-01",
|
val: "2018-03-01",
|
||||||
f: ValidateRFC3339TimeString,
|
f: ValidateRFC3339TimeString,
|
||||||
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`cannot parse "" as "T"`)),
|
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`invalid RFC3339 timestamp`)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
val: "2018-03-01T",
|
val: "2018-03-01T",
|
||||||
f: ValidateRFC3339TimeString,
|
f: ValidateRFC3339TimeString,
|
||||||
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`cannot parse "" as "15"`)),
|
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`invalid RFC3339 timestamp`)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
val: "2018-03-01T00:00:00",
|
val: "2018-03-01T00:00:00",
|
||||||
f: ValidateRFC3339TimeString,
|
f: ValidateRFC3339TimeString,
|
||||||
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`cannot parse "" as "Z07:00"`)),
|
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`invalid RFC3339 timestamp`)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
val: "2018-03-01T00:00:00Z05:00",
|
val: "2018-03-01T00:00:00Z05:00",
|
||||||
f: ValidateRFC3339TimeString,
|
f: ValidateRFC3339TimeString,
|
||||||
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`extra text: 05:00`)),
|
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`invalid RFC3339 timestamp`)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
val: "2018-03-01T00:00:00Z-05:00",
|
val: "2018-03-01T00:00:00Z-05:00",
|
||||||
f: ValidateRFC3339TimeString,
|
f: ValidateRFC3339TimeString,
|
||||||
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`extra text: -05:00`)),
|
expectedErr: regexp.MustCompile(regexp.QuoteMeta(`invalid RFC3339 timestamp`)),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue