diff --git a/internal/log/formatter.go b/internal/log/formatter.go index 4db6913c..db067d12 100644 --- a/internal/log/formatter.go +++ b/internal/log/formatter.go @@ -128,11 +128,11 @@ func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) { func trimFilename(s string) string { const sub = "pg_timetable/internal/" - idx := strings.Index(s, sub) - if idx == -1 { + _, after, ok := strings.Cut(s, sub) + if !ok { return s } - return s[idx+len(sub):] + return after } func (f *Formatter) writeCaller(b *bytes.Buffer, entry *logrus.Entry) { diff --git a/internal/pgengine/access_test.go b/internal/pgengine/access_test.go index 77d8209f..825c31c9 100644 --- a/internal/pgengine/access_test.go +++ b/internal/pgengine/access_test.go @@ -67,7 +67,7 @@ func TestSelectChains(t *testing.T) { pge := pgengine.NewDB(mockPool, "pgengine_unit_test") defer mockPool.Close() - for i := 0; i < 3; i++ { + for range 3 { mockPool.ExpectQuery("SELECT.+chain_id").WithArgs(pgxmock.AnyArg()).WillReturnError(errors.New("error")) mockPool.ExpectQuery("SELECT.+chain_id").WithArgs(pgxmock.AnyArg()).WillReturnRows(pgxmock.NewRows([]string{"foo"}).AddRow("baz")) } diff --git a/internal/pgengine/bootstrap_test.go b/internal/pgengine/bootstrap_test.go index 461a7231..02cef91d 100644 --- a/internal/pgengine/bootstrap_test.go +++ b/internal/pgengine/bootstrap_test.go @@ -50,7 +50,7 @@ func TestExecuteSchemaScripts(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() mockPool.ExpectQuery("SELECT EXISTS").WillReturnRows(pgxmock.NewRows([]string{"exists"}).AddRow(false)) - for i := 0; i < 5; i++ { + for range 5 { mockPool.ExpectExec(".*").WillReturnResult(pgxmock.NewResult("EXECUTE", 1)) } assert.NoError(t, mockpge.ExecuteSchemaScripts(ctx)) diff --git a/internal/pgengine/log_hook_test.go b/internal/pgengine/log_hook_test.go index 67be8cea..dad456c2 100644 --- a/internal/pgengine/log_hook_test.go +++ b/internal/pgengine/log_hook_test.go @@ -59,8 +59,7 @@ func TestCancelledContext(t *testing.T) { } func TestFireError(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + ctx := t.Context() h := NewHook(ctx, &PgEngine{}, "debug") err := errors.New("fire error") go func() { h.lastError <- err }() diff --git a/internal/scheduler/shell_test.go b/internal/scheduler/shell_test.go index 8804619f..5b6675d2 100644 --- a/internal/scheduler/shell_test.go +++ b/internal/scheduler/shell_test.go @@ -24,9 +24,9 @@ type testCommander struct{} // overwrite CombinedOutput function of os/exec so only parameter syntax and return codes are checked... func (c testCommander) CombinedOutput(_ context.Context, command string, args ...string) ([]byte, error) { if strings.HasPrefix(command, "ping") { - return []byte(fmt.Sprint(command, args)), nil + return fmt.Append(nil, command, args), nil } - return []byte(fmt.Sprintf("Command %s not found", command)), &exec.Error{Name: command, Err: exec.ErrNotFound} + return fmt.Appendf(nil, "Command %s not found", command), &exec.Error{Name: command, Err: exec.ErrNotFound} } func TestShellCommandDuration(t *testing.T) { diff --git a/internal/tasks/files_test.go b/internal/tasks/files_test.go index f344a820..b2c5714a 100644 --- a/internal/tasks/files_test.go +++ b/internal/tasks/files_test.go @@ -19,7 +19,7 @@ var ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http } w.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=\"%s\"", "test.txt")) bw := bufio.NewWriterSize(w, 4096) - for i := 0; i < 4096; i++ { + for i := range 4096 { _, _ = bw.Write([]byte{byte(i)}) } _ = bw.Flush()