Skip to content

Commit

Permalink
internal/keyvaluetags: Support []string with New()
Browse files Browse the repository at this point in the history
Reference: #7926
  • Loading branch information
bflad committed Oct 7, 2019
1 parent be01d68 commit 62be6a5
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
8 changes: 8 additions & 0 deletions aws/internal/keyvaluetags/key_value_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ func New(i interface{}) KeyValueTags {
kvtm[k] = &str
}

return kvtm
case []string:
kvtm := make(KeyValueTags, len(value))

for _, v := range value {
kvtm[v] = nil
}

return kvtm
case []interface{}:
kvtm := make(KeyValueTags, len(value))
Expand Down
76 changes: 74 additions & 2 deletions aws/internal/keyvaluetags/key_value_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,45 @@ func TestKeyValueTagsKeys(t *testing.T) {
want []string
}{
{
name: "empty",
name: "empty_map_string_interface",
tags: New(map[string]interface{}{}),
want: []string{},
},
{
name: "empty_map_string_stringPointer",
tags: New(map[string]*string{}),
want: []string{},
},
{
name: "empty_map_string_string",
tags: New(map[string]string{}),
want: []string{},
},
{
name: "non_empty",
name: "empty_slice_interface",
tags: New(map[string]interface{}{}),
want: []string{},
},
{
name: "empty_slice_string",
tags: New(map[string]string{}),
want: []string{},
},
{
name: "non_empty_map_string_interface",
tags: New(map[string]interface{}{
"key1": "value1",
"key2": "value2",
"key3": "value3",
}),
want: []string{
"key1",
"key2",
"key3",
},
},
{
name: "non_empty_map_string_string",
tags: New(map[string]string{
"key1": "value1",
"key2": "value2",
Expand All @@ -273,6 +306,45 @@ func TestKeyValueTagsKeys(t *testing.T) {
"key3",
},
},
{
name: "non_empty_map_string_stringPointer",
tags: New(map[string]*string{
"key1": testStringPtr("value1"),
"key2": testStringPtr("value2"),
"key3": testStringPtr("value3"),
}),
want: []string{
"key1",
"key2",
"key3",
},
},
{
name: "non_empty_slice_interface",
tags: New([]interface{}{
"key1",
"key2",
"key3",
}),
want: []string{
"key1",
"key2",
"key3",
},
},
{
name: "non_empty_slice_string",
tags: New([]string{
"key1",
"key2",
"key3",
}),
want: []string{
"key1",
"key2",
"key3",
},
},
}

for _, testCase := range testCases {
Expand Down

0 comments on commit 62be6a5

Please sign in to comment.