mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Handle 'not supplied' case for field type TypeNameString (#3546)
* Fix panic if value is not supplied for variables of TypeNameString * Add tests for 'not supplied' case of all field types
This commit is contained in:
@@ -604,6 +604,8 @@ func (s *FieldSchema) DefaultOrZero() interface{} {
|
||||
// Zero returns the correct zero-value for a specific FieldType
|
||||
func (t FieldType) Zero() interface{} {
|
||||
switch t {
|
||||
case TypeNameString:
|
||||
return ""
|
||||
case TypeString:
|
||||
return ""
|
||||
case TypeInt:
|
||||
|
||||
@@ -278,6 +278,87 @@ func TestFieldDataGet(t *testing.T) {
|
||||
"foo",
|
||||
"bar.baz-bay123",
|
||||
},
|
||||
|
||||
"name string type, not supplied": {
|
||||
map[string]*FieldSchema{
|
||||
"foo": {Type: TypeNameString},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
"foo",
|
||||
"",
|
||||
},
|
||||
|
||||
"string type, not supplied": {
|
||||
map[string]*FieldSchema{
|
||||
"foo": {Type: TypeString},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
"foo",
|
||||
"",
|
||||
},
|
||||
|
||||
"type int, not supplied": {
|
||||
map[string]*FieldSchema{
|
||||
"foo": {Type: TypeInt},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
"foo",
|
||||
0,
|
||||
},
|
||||
|
||||
"type bool, not supplied": {
|
||||
map[string]*FieldSchema{
|
||||
"foo": {Type: TypeBool},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
"foo",
|
||||
false,
|
||||
},
|
||||
|
||||
"type map, not supplied": {
|
||||
map[string]*FieldSchema{
|
||||
"foo": {Type: TypeMap},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
"foo",
|
||||
map[string]interface{}{},
|
||||
},
|
||||
|
||||
"type duration second, not supplied": {
|
||||
map[string]*FieldSchema{
|
||||
"foo": {Type: TypeDurationSecond},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
"foo",
|
||||
0,
|
||||
},
|
||||
|
||||
"type slice, not supplied": {
|
||||
map[string]*FieldSchema{
|
||||
"foo": {Type: TypeSlice},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
"foo",
|
||||
[]interface{}{},
|
||||
},
|
||||
|
||||
"type string slice, not supplied": {
|
||||
map[string]*FieldSchema{
|
||||
"foo": {Type: TypeStringSlice},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
"foo",
|
||||
[]string{},
|
||||
},
|
||||
|
||||
"type comma string slice, not supplied": {
|
||||
map[string]*FieldSchema{
|
||||
"foo": {Type: TypeCommaStringSlice},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
"foo",
|
||||
[]string{},
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
|
||||
Reference in New Issue
Block a user