@@ -6,17 +6,12 @@ import (
66 "context"
77 "github.com/DATA-DOG/go-sqlmock"
88 "github.com/stretchr/testify/assert"
9- "quesma/ab_testing"
109 "quesma/clickhouse"
1110 "quesma/concurrent"
12- "quesma/logger"
1311 "quesma/model"
1412 "quesma/queryparser"
1513 "quesma/quesma/types"
16- "quesma/quesma/ui"
1714 "quesma/schema"
18- "quesma/table_resolver"
19- "quesma/telemetry"
2015 "quesma/testdata"
2116 "quesma/util"
2217 "strconv"
@@ -50,19 +45,9 @@ func TestSearchOpensearch(t *testing.T) {
5045 t .Run (strconv .Itoa (i )+ tt .Name , func (t * testing.T ) {
5146 db , mock := util .InitSqlMockWithPrettySqlAndPrint (t , false )
5247 defer db .Close ()
53- lm := clickhouse .NewLogManagerWithConnection (db , concurrent .NewMapWith (tableName , & table ))
54- resolver := table_resolver .NewEmptyTableResolver ()
55- resolver .Decisions [tableName ] = & table_resolver.Decision {
56- UseConnectors : []table_resolver.ConnectorDecision {
57- & table_resolver.ConnectorDecisionClickhouse {
58- ClickhouseTableName : tableName ,
59- ClickhouseTables : []string {tableName },
60- },
61- },
62- }
6348
64- managementConsole := ui . NewQuesmaManagementConsole ( & DefaultConfig , nil , nil , make ( <- chan logger. LogWithLevel , 50000 ), telemetry . NewPhoneHomeEmptyAgent (), nil , resolver )
65- cw := queryparser.ClickhouseQueryTranslator {ClickhouseLM : lm , Table : & table , Ctx : context .Background (), Schema : s .Tables [tableName ], Config : & DefaultConfig }
49+ queryRunner := NewQueryRunnerDefaultForTests ( db , & DefaultConfig , tableName , concurrent . NewMapWith ( tableName , & table ), s )
50+ cw := queryparser.ClickhouseQueryTranslator {ClickhouseLM : queryRunner . logManager , Table : & table , Ctx : context .Background (), Schema : s .Tables [tableName ], Config : & DefaultConfig }
6651
6752 body , parseErr := types .ParseJSON (tt .QueryJson )
6853 assert .NoError (t , parseErr )
@@ -76,7 +61,7 @@ func TestSearchOpensearch(t *testing.T) {
7661 for _ , wantedQuery := range tt .WantedQueries {
7762 mock .ExpectQuery (wantedQuery ).WillReturnRows (sqlmock .NewRows ([]string {"@timestamp" , "host.name" }))
7863 }
79- queryRunner := NewQueryRunner ( lm , & DefaultConfig , nil , managementConsole , s , ab_testing . NewEmptySender (), resolver )
64+
8065 _ , err2 := queryRunner .handleSearch (ctx , tableName , types .MustJSON (tt .QueryJson ))
8166 assert .NoError (t , err2 )
8267
@@ -203,28 +188,16 @@ func TestHighlighter(t *testing.T) {
203188 }
204189 db , mock := util .InitSqlMockWithPrettyPrint (t , true )
205190 defer db .Close ()
206- lm := clickhouse .NewLogManagerWithConnection (db , concurrent .NewMapWith (tableName , & table ))
207-
208- resolver := table_resolver .NewEmptyTableResolver ()
209- resolver .Decisions [tableName ] = & table_resolver.Decision {
210- UseConnectors : []table_resolver.ConnectorDecision {
211- & table_resolver.ConnectorDecisionClickhouse {
212- ClickhouseTableName : tableName ,
213- ClickhouseTables : []string {tableName },
214- },
215- },
216- }
217-
218- managementConsole := ui .NewQuesmaManagementConsole (& DefaultConfig , nil , nil , make (<- chan logger.LogWithLevel , 50000 ), telemetry .NewPhoneHomeEmptyAgent (), nil , resolver )
219191
220- mock .ExpectQuery ("" ).WillReturnRows (sqlmock .NewRows ([]string {"message$*%:;" , "host.name" , "@timestamp" }). // careful, it's not always in this order, order is nondeterministic
221- AddRow ("abcd" , "abcd" , "abcd" ).
222- AddRow ("prefix-text-to-highlight" , "prefix-text-to-highlight" , "prefix-text-to-highlight" ).
223- AddRow ("text-to-highlight-suffix" , "text-to-highlight-suffix" , "text-to-highlight-suffix" ).
224- AddRow ("text-to-highlight" , "text-to-highlight" , "text-to-highlight" ).
225- AddRow ("text" , "text" , "text" ))
192+ // careful, it's not always in this order, order is nondeterministic
193+ mock .ExpectQuery ("" ).WillReturnRows (sqlmock .NewRows ([]string {"message$*%:;" , "host.name" , "@timestamp" }).
194+ AddRow ("abcd" , "abcd" , "abcd" ).
195+ AddRow ("prefix-text-to-highlight" , "prefix-text-to-highlight" , "prefix-text-to-highlight" ).
196+ AddRow ("text-to-highlight-suffix" , "text-to-highlight-suffix" , "text-to-highlight-suffix" ).
197+ AddRow ("text-to-highlight" , "text-to-highlight" , "text-to-highlight" ).
198+ AddRow ("text" , "text" , "text" ))
226199
227- queryRunner := NewQueryRunner ( lm , & DefaultConfig , nil , managementConsole , s , ab_testing . NewEmptySender ( ), resolver )
200+ queryRunner := NewQueryRunnerDefaultForTests ( db , & DefaultConfig , tableName , concurrent . NewMapWith ( tableName , & table ), s )
228201 response , err := queryRunner .handleSearch (ctx , tableName , types .MustJSON (query ))
229202 assert .NoError (t , err )
230203 if err != nil {
0 commit comments