apiserver/folders: use exact match on GetFolderByTitle in legacy (#106867)
* apiserver/folders: use exact match on GetFolderByTitle in legacy Signed-off-by: Maicon Costa <maiconscosta@gmail.com> --------- Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
This commit is contained in:
@@ -43,11 +43,16 @@ func (f OrgFilter) Where() (string, []any) {
|
||||
}
|
||||
|
||||
type TitleFilter struct {
|
||||
Dialect migrator.Dialect
|
||||
Title string
|
||||
Dialect migrator.Dialect
|
||||
Title string
|
||||
TitleExactMatch bool
|
||||
}
|
||||
|
||||
func (f TitleFilter) Where() (string, []any) {
|
||||
if f.TitleExactMatch {
|
||||
return "dashboard.title = ?", []any{f.Title}
|
||||
}
|
||||
|
||||
sql, params := f.Dialect.LikeOperator("dashboard.title", true, f.Title, true)
|
||||
return sql, []any{params}
|
||||
}
|
||||
|
||||
@@ -91,3 +91,44 @@ func TestFolderUIDFilter(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTitleFilter(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
title string
|
||||
exactMatch bool
|
||||
expectedSql string
|
||||
expectedParams []any
|
||||
}{
|
||||
{
|
||||
description: "searching foo folder - partial match",
|
||||
title: "foo",
|
||||
expectedSql: "dashboard.title LIKE ?",
|
||||
expectedParams: []any{"%foo%"},
|
||||
},
|
||||
{
|
||||
description: "searching foo folder - exact match",
|
||||
title: "foo",
|
||||
exactMatch: true,
|
||||
expectedSql: "dashboard.title = ?",
|
||||
expectedParams: []any{"foo"},
|
||||
},
|
||||
}
|
||||
|
||||
store := setupTestEnvironment(t)
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
f := searchstore.TitleFilter{
|
||||
Dialect: store.GetDialect(),
|
||||
Title: tc.title,
|
||||
TitleExactMatch: tc.exactMatch,
|
||||
}
|
||||
|
||||
sql, params := f.Where()
|
||||
|
||||
assert.Equal(t, tc.expectedSql, sql)
|
||||
assert.Equal(t, tc.expectedParams, params)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user