diff --git a/logical/framework/backend.go b/logical/framework/backend.go index 477a926fc954..4b9b8b949ad9 100644 --- a/logical/framework/backend.go +++ b/logical/framework/backend.go @@ -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: diff --git a/logical/framework/field_data_test.go b/logical/framework/field_data_test.go index a9bc474eea56..90c1660c0734 100644 --- a/logical/framework/field_data_test.go +++ b/logical/framework/field_data_test.go @@ -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 {