Skip to content

Commit

Permalink
Merge pull request #2070 from anyproto/go-4814-the-image-is-not-delet…
Browse files Browse the repository at this point in the history
…ed-from-the-space-and-profile-icons

GO-4814: Fix detail validator for string list wrapper
  • Loading branch information
deff7 authored Jan 31, 2025
2 parents de637a7 + 5a647fc commit 4aabdf7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/domain/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ func (v Value) TryWrapToStringList() ([]string, bool) {
}
s, ok := v.TryString()
if ok {
return []string{s}, true
if s == "" {
return []string{}, true
} else {
return []string{s}, true
}
}
return nil, false
}
Expand Down
40 changes: 40 additions & 0 deletions core/domain/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,43 @@ func TestValue_Empty(t *testing.T) {
assert.Equal(t, tc.want, tc.value.IsEmpty())
}
}

func TestTryWrapToStringList(t *testing.T) {
for i, tc := range []struct {
in Value
want []string
wantOk bool
}{
{
in: String(""),
want: []string{},
wantOk: true,
},
{
in: String("foo"),
want: []string{"foo"},
wantOk: true,
},
{
in: StringList([]string{"foo", "bar"}),
want: []string{"foo", "bar"},
wantOk: true,
},
{
in: Float64(123.456),
want: nil,
wantOk: false,
},
{
in: Invalid(),
want: nil,
wantOk: false,
},
} {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
got, gotOk := tc.in.TryWrapToStringList()
assert.Equal(t, tc.want, got)
assert.Equal(t, tc.wantOk, gotOk)
})
}
}

0 comments on commit 4aabdf7

Please sign in to comment.