Refactor and fix tagger test

This commit is contained in:
Jan Eitzinger 2025-06-06 16:41:48 +02:00
parent 87c93e90cd
commit 0373010497
3 changed files with 5 additions and 5 deletions

View File

@ -15,13 +15,13 @@ import (
type Hooks struct{} type Hooks struct{}
// Before hook will print the query with it's args and return the context with the timestamp // Before hook will print the query with it's args and return the context with the timestamp
func (h *Hooks) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error) { func (h *Hooks) Before(ctx context.Context, query string, args ...any) (context.Context, error) {
log.Debugf("SQL query %s %q", query, args) log.Debugf("SQL query %s %q", query, args)
return context.WithValue(ctx, "begin", time.Now()), nil return context.WithValue(ctx, "begin", time.Now()), nil
} }
// After hook will get the timestamp registered on the Before hook and print the elapsed time // After hook will get the timestamp registered on the Before hook and print the elapsed time
func (h *Hooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error) { func (h *Hooks) After(ctx context.Context, query string, args ...any) (context.Context, error) {
begin := ctx.Value("begin").(time.Time) begin := ctx.Value("begin").(time.Time)
log.Debugf("Took: %s\n", time.Since(begin)) log.Debugf("Took: %s\n", time.Since(begin))
return ctx, nil return ctx, nil

View File

@ -686,7 +686,7 @@ func (r *JobRepository) jobsMetricStatisticsHistogram(
mainQuery := sq.Select( mainQuery := sq.Select(
fmt.Sprintf(`%s + 1 as bin`, binQuery), fmt.Sprintf(`%s + 1 as bin`, binQuery),
fmt.Sprintf(`count(*) as count`), `count(*) as count`,
// For Debug: // fmt.Sprintf(`CAST((%f / %d) as INTEGER ) * %s as min`, peak, *bins, binQuery), // For Debug: // fmt.Sprintf(`CAST((%f / %d) as INTEGER ) * %s as min`, peak, *bins, binQuery),
// For Debug: // fmt.Sprintf(`CAST((%f / %d) as INTEGER ) * (%s + 1) as max`, peak, *bins, binQuery), // For Debug: // fmt.Sprintf(`CAST((%f / %d) as INTEGER ) * (%s + 1) as max`, peak, *bins, binQuery),
).From("job").Where( ).From("job").Where(

View File

@ -35,8 +35,8 @@ func TestRegister(t *testing.T) {
err := tagger.Register() err := tagger.Register()
noErr(t, err) noErr(t, err)
if len(tagger.apps) != 4 { if len(tagger.apps) != 14 {
t.Errorf("wrong summary for diagnostic \ngot: %d \nwant: 3", len(tagger.apps)) t.Errorf("wrong summary for diagnostic \ngot: %d \nwant: 14", len(tagger.apps))
} }
} }