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:
maicon
2025-06-24 17:42:08 -03:00
committed by GitHub
parent 988d889ba7
commit 8a05378ef3
9 changed files with 150 additions and 25 deletions
+7 -2
View File
@@ -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)
})
}
}