mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
sdk/framework: add TypeSignedDurationSecond FieldType (#6989)
* Refactor table driven tests to use subtests * sdk/framework: add TypeSignedDurationSecond FieldType Adds the TypeSignedDurationSecond FieldType which accepts positive and negative durations. The existing TypeDurationSecond FieldType does not accept negative durations. * Add tests for 0 for TypeDurationSecond and TypeSignedDurationSecond
This commit is contained in:
@@ -38,8 +38,8 @@ func (d *FieldData) Validate() error {
|
||||
}
|
||||
|
||||
switch schema.Type {
|
||||
case TypeBool, TypeInt, TypeMap, TypeDurationSecond, TypeString, TypeLowerCaseString,
|
||||
TypeNameString, TypeSlice, TypeStringSlice, TypeCommaStringSlice,
|
||||
case TypeBool, TypeInt, TypeMap, TypeDurationSecond, TypeSignedDurationSecond, TypeString,
|
||||
TypeLowerCaseString, TypeNameString, TypeSlice, TypeStringSlice, TypeCommaStringSlice,
|
||||
TypeKVPairs, TypeCommaIntSlice, TypeHeader:
|
||||
_, _, err := d.getPrimitive(field, schema)
|
||||
if err != nil {
|
||||
@@ -131,8 +131,8 @@ func (d *FieldData) GetOkErr(k string) (interface{}, bool, error) {
|
||||
}
|
||||
|
||||
switch schema.Type {
|
||||
case TypeBool, TypeInt, TypeMap, TypeDurationSecond, TypeString, TypeLowerCaseString,
|
||||
TypeNameString, TypeSlice, TypeStringSlice, TypeCommaStringSlice,
|
||||
case TypeBool, TypeInt, TypeMap, TypeDurationSecond, TypeSignedDurationSecond, TypeString,
|
||||
TypeLowerCaseString, TypeNameString, TypeSlice, TypeStringSlice, TypeCommaStringSlice,
|
||||
TypeKVPairs, TypeCommaIntSlice, TypeHeader:
|
||||
return d.getPrimitive(k, schema)
|
||||
default:
|
||||
@@ -147,7 +147,7 @@ func (d *FieldData) getPrimitive(k string, schema *FieldSchema) (interface{}, bo
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
switch schema.Type {
|
||||
switch t := schema.Type; t {
|
||||
case TypeBool:
|
||||
var result bool
|
||||
if err := mapstructure.WeakDecode(raw, &result); err != nil {
|
||||
@@ -197,7 +197,7 @@ func (d *FieldData) getPrimitive(k string, schema *FieldSchema) (interface{}, bo
|
||||
}
|
||||
return result, true, nil
|
||||
|
||||
case TypeDurationSecond:
|
||||
case TypeDurationSecond, TypeSignedDurationSecond:
|
||||
var result int
|
||||
switch inp := raw.(type) {
|
||||
case nil:
|
||||
@@ -209,7 +209,7 @@ func (d *FieldData) getPrimitive(k string, schema *FieldSchema) (interface{}, bo
|
||||
}
|
||||
result = int(dur.Seconds())
|
||||
}
|
||||
if result < 0 {
|
||||
if t == TypeDurationSecond && result < 0 {
|
||||
return nil, false, fmt.Errorf("cannot provide negative value '%d'", result)
|
||||
}
|
||||
return result, true, nil
|
||||
|
||||
Reference in New Issue
Block a user