@@ -76,15 +76,15 @@ func TestPGStateStatementsCollectorWithStatement(t *testing.T) {
7676
7777 inst := & instance {db : db , version : semver .MustParse ("12.0.0" )}
7878
79- columns := []string {"user" , "datname" , "queryid" , "query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
79+ columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 100) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
8080 rows := sqlmock .NewRows (columns ).
8181 AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 )
82- mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsQuery , pgStatStatementQuerySelect ))).WillReturnRows (rows )
82+ mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsQuery , fmt . Sprintf ( pgStatStatementQuerySelect , 100 ) ))).WillReturnRows (rows )
8383
8484 ch := make (chan prometheus.Metric )
8585 go func () {
8686 defer close (ch )
87- c := PGStatStatementsCollector {includeQueryStatement : true }
87+ c := PGStatStatementsCollector {includeQueryStatement : true , statementLength : 100 }
8888
8989 if err := c .Update (context .Background (), inst , ch ); err != nil {
9090 t .Errorf ("Error calling PGStatStatementsCollector.Update: %s" , err )
@@ -163,15 +163,15 @@ func TestPGStateStatementsCollectorNullWithStatement(t *testing.T) {
163163
164164 inst := & instance {db : db , version : semver .MustParse ("13.3.7" )}
165165
166- columns := []string {"user" , "datname" , "queryid" , "query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
166+ columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 200) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
167167 rows := sqlmock .NewRows (columns ).
168168 AddRow (nil , nil , nil , nil , nil , nil , nil , nil , nil )
169- mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , pgStatStatementQuerySelect ))).WillReturnRows (rows )
169+ mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , fmt . Sprintf ( pgStatStatementQuerySelect , 200 ) ))).WillReturnRows (rows )
170170
171171 ch := make (chan prometheus.Metric )
172172 go func () {
173173 defer close (ch )
174- c := PGStatStatementsCollector {includeQueryStatement : true }
174+ c := PGStatStatementsCollector {includeQueryStatement : true , statementLength : 200 }
175175
176176 if err := c .Update (context .Background (), inst , ch ); err != nil {
177177 t .Errorf ("Error calling PGStatStatementsCollector.Update: %s" , err )
@@ -250,15 +250,15 @@ func TestPGStateStatementsCollectorNewPGWithStatement(t *testing.T) {
250250
251251 inst := & instance {db : db , version : semver .MustParse ("13.3.7" )}
252252
253- columns := []string {"user" , "datname" , "queryid" , "query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
253+ columns := []string {"user" , "datname" , "queryid" , "LEFT(pg_stat_statements.query, 300) as query" , "calls_total" , "seconds_total" , "rows_total" , "block_read_seconds_total" , "block_write_seconds_total" }
254254 rows := sqlmock .NewRows (columns ).
255255 AddRow ("postgres" , "postgres" , 1500 , "select 1 from foo" , 5 , 0.4 , 100 , 0.1 , 0.2 )
256- mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , pgStatStatementQuerySelect ))).WillReturnRows (rows )
256+ mock .ExpectQuery (sanitizeQuery (fmt .Sprintf (pgStatStatementsNewQuery , fmt . Sprintf ( pgStatStatementQuerySelect , 300 ) ))).WillReturnRows (rows )
257257
258258 ch := make (chan prometheus.Metric )
259259 go func () {
260260 defer close (ch )
261- c := PGStatStatementsCollector {includeQueryStatement : true }
261+ c := PGStatStatementsCollector {includeQueryStatement : true , statementLength : 300 }
262262
263263 if err := c .Update (context .Background (), inst , ch ); err != nil {
264264 t .Errorf ("Error calling PGStatStatementsCollector.Update: %s" , err )
0 commit comments