Skip to content

Commit

Permalink
Handle 'not supplied' case for field type TypeNameString (#3546)
Browse files Browse the repository at this point in the history
* Fix panic if value is not supplied for variables of TypeNameString

* Add tests for 'not supplied' case of all field types
  • Loading branch information
vishalnayak authored Nov 7, 2017
1 parent 1cf3414 commit 2994b26
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions logical/framework/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
81 changes: 81 additions & 0 deletions logical/framework/field_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2994b26

Please sign in to comment.