@@ -164,6 +164,57 @@ func TestSearchWorkspace(t *testing.T) {
164
164
})
165
165
}
166
166
167
+ func TestSearchAudit (t * testing.T ) {
168
+ t .Parallel ()
169
+ testCases := []struct {
170
+ Name string
171
+ Query string
172
+ Expected database.GetAuditLogsOffsetParams
173
+ ExpectedErrorContains string
174
+ }{
175
+ {
176
+ Name : "Empty" ,
177
+ Query : "" ,
178
+ Expected : database.GetAuditLogsOffsetParams {},
179
+ },
180
+ // Failures
181
+ {
182
+ Name : "ExtraColon" ,
183
+ Query : `search:name:extra` ,
184
+ ExpectedErrorContains : "can only contain 1 ':'" ,
185
+ },
186
+ {
187
+ Name : "ExtraKeys" ,
188
+ Query : `foo:bar` ,
189
+ ExpectedErrorContains : `Query param "foo" is not a valid query param` ,
190
+ },
191
+ {
192
+ Name : "Dates" ,
193
+ Query : "date_from:2006" ,
194
+ ExpectedErrorContains : "valid date format" ,
195
+ },
196
+ }
197
+
198
+ for _ , c := range testCases {
199
+ c := c
200
+ t .Run (c .Name , func (t * testing.T ) {
201
+ t .Parallel ()
202
+ values , errs := searchquery .Audit (c .Query )
203
+ if c .ExpectedErrorContains != "" {
204
+ require .True (t , len (errs ) > 0 , "expect some errors" )
205
+ var s strings.Builder
206
+ for _ , err := range errs {
207
+ _ , _ = s .WriteString (fmt .Sprintf ("%s: %s\n " , err .Field , err .Detail ))
208
+ }
209
+ require .Contains (t , s .String (), c .ExpectedErrorContains )
210
+ } else {
211
+ require .Len (t , errs , 0 , "expected no error" )
212
+ require .Equal (t , c .Expected , values , "expected values" )
213
+ }
214
+ })
215
+ }
216
+ }
217
+
167
218
func TestSearchUsers (t * testing.T ) {
168
219
t .Parallel ()
169
220
testCases := []struct {
0 commit comments