@@ -174,6 +174,94 @@ func TestSeriesRepositoryList(t *testing.T) {
174174 })
175175}
176176
177+ // nolint: dupl
178+ func TestSeriesRepositorySearch (t * testing.T ) {
179+ client , ctx := NewTransientDB (t )
180+ repo := NewSeriesRepository (client )
181+
182+ series1 := & Series {
183+ ExtID : "series-search-1" ,
184+ Title : "Kernel Series for ARM64" ,
185+ PublishedAt : time .Date (2020 , time .January , 1 , 1 , 0 , 0 , 0 , time .UTC ),
186+ }
187+ patches1 := []* Patch {
188+ {
189+ Title : "arm64: patch for CPU" ,
190+ Seq : 1 ,
191+ },
192+ {
193+ Title : "arm64: another patch for memory" ,
194+ Seq : 2 ,
195+ },
196+ }
197+ err := repo .Insert (ctx , series1 , func () ([]* Patch , error ) {
198+ return patches1 , nil
199+ })
200+ assert .NoError (t , err )
201+
202+ series2 := & Series {
203+ ExtID : "series-search-2" ,
204+ Title : "X86 Specific Patch Series" ,
205+ PublishedAt : time .Date (2020 , time .January , 1 , 2 , 0 , 0 , 0 , time .UTC ),
206+ }
207+ patches2 := []* Patch {
208+ {
209+ Title : "x86: new feature" ,
210+ Seq : 1 ,
211+ },
212+ }
213+ err = repo .Insert (ctx , series2 , func () ([]* Patch , error ) {
214+ return patches2 , nil
215+ })
216+ assert .NoError (t , err )
217+
218+ series3 := & Series {
219+ ExtID : "series-search-3" ,
220+ Title : "Generic Bug Fixes" ,
221+ PublishedAt : time .Date (2020 , time .January , 1 , 3 , 0 , 0 , 0 , time .UTC ),
222+ }
223+ patches3 := []* Patch {
224+ {
225+ Title : "net: fix double free" ,
226+ Seq : 1 ,
227+ },
228+ }
229+ err = repo .Insert (ctx , series3 , func () ([]* Patch , error ) {
230+ return patches3 , nil
231+ })
232+ assert .NoError (t , err )
233+
234+ t .Run ("by_series_name" , func (t * testing.T ) {
235+ list , err := repo .ListLatest (ctx , SeriesFilter {Name : "Kernel Series" }, time.Time {})
236+ assert .NoError (t , err )
237+ assert .Len (t , list , 1 )
238+ assert .Equal (t , series1 .Title , list [0 ].Series .Title )
239+ })
240+ t .Run ("by_patch_name" , func (t * testing.T ) {
241+ list , err := repo .ListLatest (ctx , SeriesFilter {Name : "double free" }, time.Time {})
242+ assert .NoError (t , err )
243+ assert .Len (t , list , 1 )
244+ assert .Equal (t , series3 .Title , list [0 ].Series .Title )
245+ })
246+ t .Run ("no_match" , func (t * testing.T ) {
247+ list , err := repo .ListLatest (ctx , SeriesFilter {Name : "nonexistent" }, time.Time {})
248+ assert .NoError (t , err )
249+ assert .Len (t , list , 0 )
250+ })
251+ t .Run ("empty_search_string" , func (t * testing.T ) {
252+ list , err := repo .ListLatest (ctx , SeriesFilter {Name : "" }, time.Time {})
253+ assert .NoError (t , err )
254+ assert .Len (t , list , 3 ) // All series should be returned if search strings are empty.
255+ })
256+ t .Run ("search_across_series_and_patch" , func (t * testing.T ) {
257+ list , err := repo .ListLatest (ctx , SeriesFilter {Name : "patch" }, time.Time {})
258+ assert .NoError (t , err )
259+ assert .Len (t , list , 2 )
260+ assert .Equal (t , series2 .Title , list [0 ].Series .Title )
261+ assert .Equal (t , series1 .Title , list [1 ].Series .Title )
262+ })
263+ }
264+
177265func TestSeriesRepositoryUpdate (t * testing.T ) {
178266 client , ctx := NewTransientDB (t )
179267 repo := NewSeriesRepository (client )
0 commit comments