mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix: return empty array if no option multi-selected (#19224)
Related: https://github.com/coder/coder/issues/19145
This commit is contained in:
+5
-1
@@ -349,7 +349,11 @@ func RichMultiSelect(inv *serpent.Invocation, richOptions RichMultiSelectOptions
|
||||
}
|
||||
|
||||
// Check selected option, convert descriptions (line) to values
|
||||
var results []string
|
||||
//
|
||||
// The function must return an initialized empty array, since it is later marshaled
|
||||
// into JSON. Otherwise, `var results []string` would be marshaled to "null".
|
||||
// See: https://github.com/golang/go/issues/27589
|
||||
results := []string{}
|
||||
for _, sel := range selected {
|
||||
custom := true
|
||||
for i, option := range richOptions.Options {
|
||||
|
||||
@@ -111,6 +111,17 @@ func TestRichMultiSelect(t *testing.T) {
|
||||
allowCustom: true,
|
||||
want: []string{"aaa", "bbb"},
|
||||
},
|
||||
{
|
||||
name: "NoOptionSelected",
|
||||
options: []codersdk.TemplateVersionParameterOption{
|
||||
{Name: "AAA", Description: "This is AAA", Value: "aaa"},
|
||||
{Name: "BBB", Description: "This is BBB", Value: "bbb"},
|
||||
{Name: "CCC", Description: "This is CCC", Value: "ccc"},
|
||||
},
|
||||
defaults: []string{},
|
||||
allowCustom: false,
|
||||
want: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user