Skip to content

Commit

Permalink
meta: linter fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Dec 3, 2024
1 parent d4bd550 commit c3d677a
Show file tree
Hide file tree
Showing 34 changed files with 77 additions and 81 deletions.
2 changes: 1 addition & 1 deletion internal/alerting/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (pd *PagerDuty) ping() error {
return fmt.Errorf("pagerduty list abilities: %v", err)
}
if len(resp.Abilities) <= 0 {
return fmt.Errorf("pagerduty: missing abilities")
return errors.New("pagerduty: missing abilities")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/alerting/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *Slack) AuthTest() error {
return fmt.Errorf("slack auth test: %v", err)
}
if resp.UserID == "" {
return fmt.Errorf("slack: missing user_id")
return errors.New("slack: missing user_id")
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/dbtest/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ func CreateTestDatabase(t *testing.T, config database.DatabaseConfig) database.D
}

dbName := "test" + base.ID()
_, err = rootDb.Exec(fmt.Sprintf("CREATE DATABASE %s", dbName))
_, err = rootDb.Exec("CREATE DATABASE " + dbName)
if err != nil {
t.Fatal(err)
}

t.Cleanup(func() {
rootDb.Exec(fmt.Sprintf("DROP DATABASE %s", dbName))
rootDb.Exec("DROP DATABASE " + dbName)
rootDb.Close()
})

Expand Down
2 changes: 1 addition & 1 deletion internal/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestEnvironment_Startup(t *testing.T) {
}

env, err := NewEnvironment(env)
a.Nil(err)
a.NoError(err)

t.Cleanup(env.Shutdown)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/incoming/odfi/prenotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"fmt"
"path/filepath"
"strconv"
"strings"

"github.com/moov-io/ach"
Expand Down Expand Up @@ -92,12 +93,12 @@ func (pc *prenoteEmitter) Handle(ctx context.Context, logger log.Logger, file Fi
"origin": log.String(file.ACHFile.Header.ImmediateOrigin),
"destination": log.String(file.ACHFile.Header.ImmediateDestination),
})
logger.Log(fmt.Sprintf("odfi: pre-notification traceNumber=%s", entries[j].TraceNumber))
logger.Log("odfi: pre-notification traceNumber=" + entries[j].TraceNumber)

prenoteEntriesProcessed.With(
"origin", file.ACHFile.Header.ImmediateOrigin,
"destination", file.ACHFile.Header.ImmediateDestination,
"transactionCode", fmt.Sprintf("%d", entries[j].TransactionCode),
"transactionCode", strconv.Itoa(entries[j].TransactionCode),
).Add(1)
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/incoming/odfi/reconciliation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestCreditReconciliation(t *testing.T) {
}
batch.AddEntry(&entry)
}
require.Equal(t, 20, len(file.Batches))
require.Len(t, file.Batches, 20)

// Set ValidateOpts similar to what Processor sets
file.SetValidation(&ach.ValidateOpts{
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestCreditReconciliation(t *testing.T) {
return len(sent) > 0
}, 5*time.Second, 100*time.Millisecond)

require.Equal(t, 499, len(sent)) // one from previous subtest
require.Len(t, sent, 499) // one from previous subtest

foundTraces := make(map[string]bool)
for i := range sent {
Expand All @@ -132,6 +132,6 @@ func TestCreditReconciliation(t *testing.T) {
require.True(t, ok)
foundTraces[event.Entry.TraceNumber] = true
}
require.Equal(t, 499, len(foundTraces)) // 499 unique trace numbers
require.Len(t, foundTraces, 499) // 499 unique trace numbers
})
}
4 changes: 2 additions & 2 deletions internal/incoming/stream/streamtest/streamtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package streamtest

import (
"context"
"fmt"

"testing"

"github.com/moov-io/achgateway/internal/incoming/stream"
Expand All @@ -36,7 +36,7 @@ func InmemStream(t *testing.T) (stream.Publisher, stream.Subscription) {
conf := &service.Config{
Inbound: service.Inbound{
InMem: &service.InMemory{
URL: fmt.Sprintf("mem://%s", t.Name()),
URL: "mem://" + t.Name(),
},
},
}
Expand Down
3 changes: 1 addition & 2 deletions internal/notify/mailslurper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package notify

import (
"fmt"
"net"
"testing"
"time"
Expand Down Expand Up @@ -50,7 +49,7 @@ func spawnMailslurp(t *testing.T) *mailslurpDeployment {
err = pool.Retry(func() error {
time.Sleep(1 * time.Second)

conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%s", dep.SMTPPort()))
conn, err := net.Dial("tcp", "localhost:"+dep.SMTPPort())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/notify/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (pd *PagerDuty) Ping() error {
return fmt.Errorf("pagerduty list abilities: %v", err)
}
if len(resp.Abilities) <= 0 {
return fmt.Errorf("pagerduty: missing abilities")
return errors.New("pagerduty: missing abilities")
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/notify/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func marshalSlackMessage(status uploadStatus, msg *Message) string {
slackMsg := fmt.Sprintf("%s %s of %s", status, msg.Direction, msg.Filename)
if msg.Hostname != "" {
if msg.Direction == Upload {
slackMsg += fmt.Sprintf(" to %s", msg.Hostname)
slackMsg += " to " + msg.Hostname
} else {
slackMsg += fmt.Sprintf(" from %s", msg.Hostname)
slackMsg += " from " + msg.Hostname
}
}
slackMsg += " with ODFI server\n"
Expand Down
2 changes: 1 addition & 1 deletion internal/pipeline/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func formatHolidayMessage(day *schedule.Day, shardName string) string {
hostname, _ := os.Hostname()

if shardName != "" {
shardName = fmt.Sprintf("for %s", shardName)
shardName = "for " + shardName
}

return strings.TrimSpace(fmt.Sprintf("%s %s so %s will skip processing %s", day.Time.Format("Jan 02"), name, hostname, shardName))
Expand Down
4 changes: 2 additions & 2 deletions internal/pipeline/events_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ func TestEventsAPI_FileUploadedErrors(t *testing.T) {
for i := range paths {
address := fmt.Sprintf("http://%s/shards/testing/pipeline/%s/file-uploaded", adminServer.BindAddr(), paths[i])
req, err := http.NewRequest("PUT", address, nil)
require.NoError(t, err, fmt.Sprintf("on address %s", address))
require.NoError(t, err, "on address "+address)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
require.Equal(t, http.StatusNotFound, resp.StatusCode, fmt.Sprintf("on address %s", address))
require.Equal(t, http.StatusNotFound, resp.StatusCode, "on address "+address)
}
})

Expand Down
2 changes: 1 addition & 1 deletion internal/pipeline/file_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func testFileReceiver(t *testing.T) *TestFileReceiver {
conf := &service.Config{
Inbound: service.Inbound{
InMem: &service.InMemory{
URL: fmt.Sprintf("mem://%s", t.Name()),
URL: "mem://" + t.Name(),
},
},
Sharding: service.Sharding{
Expand Down
2 changes: 1 addition & 1 deletion internal/pipeline/manual_cutoff_times_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestFileReceiver__ManualCutoffErr(t *testing.T) {
require.NoError(t, err)

require.Len(t, resp.Shards, 1)
require.Equal(t, *resp.Shards["testing"], "bad thing")
require.Equal(t, "bad thing", *resp.Shards["testing"])
}

func setupFileReceiver(t *testing.T, waiterResponse error) (*FileReceiver, *sync.WaitGroup) {
Expand Down
10 changes: 5 additions & 5 deletions internal/pipeline/merging.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (m *filesystemMerging) writeACHFile(ctx context.Context, xfer incoming.ACHF
}

fileID := strings.TrimSuffix(xfer.FileID, ".ach")
path := filepath.Join("mergable", m.shard.Name, fmt.Sprintf("%s.ach", fileID))
path := filepath.Join("mergable", m.shard.Name, fileID+".ach")
if err := m.storage.WriteFile(path, buf.Bytes()); err != nil {
return err
}
Expand All @@ -119,7 +119,7 @@ func (m *filesystemMerging) writeACHFile(ctx context.Context, xfer incoming.ACHF
}).Logf("ERROR encoding ValidateOpts: %v", err)
}

path := filepath.Join("mergable", m.shard.Name, fmt.Sprintf("%s.json", fileID))
path := filepath.Join("mergable", m.shard.Name, fileID+".json")
if err := m.storage.WriteFile(path, buf.Bytes()); err != nil {
m.logger.Warn().With(log.Fields{
"fileID": log.String(xfer.FileID),
Expand All @@ -140,7 +140,7 @@ func (m *filesystemMerging) HandleCancel(ctx context.Context, cancel incoming.Ca
defer span.End()

fileID := strings.TrimSuffix(cancel.FileID, ".ach")
path := filepath.Join("mergable", m.shard.Name, fmt.Sprintf("%s.ach", fileID))
path := filepath.Join("mergable", m.shard.Name, fileID+".ach")

// Check if the file exists already
originalFile, _ := m.storage.Open(path)
Expand Down Expand Up @@ -563,7 +563,7 @@ func (m *filesystemMerging) saveMergedFile(ctx context.Context, dir string, file
}

name := hash(buf.Bytes())
path := filepath.Join(dir, fmt.Sprintf("%s.ach", name))
path := filepath.Join(dir, name+".ach")

span.SetAttributes(
attribute.String("achgateway.merged_filename", path),
Expand All @@ -584,7 +584,7 @@ func (m *filesystemMerging) saveMergedFile(ctx context.Context, dir string, file
return fmt.Errorf("marshal of merged ACH file validate opts: %w", err)
}

path = filepath.Join(dir, fmt.Sprintf("%s.json", name))
path = filepath.Join(dir, name+".json")
err = m.storage.WriteFile(path, buf.Bytes())
if err != nil {
return fmt.Errorf("writing merged ACH file validate opts: %w", err)
Expand Down
28 changes: 14 additions & 14 deletions internal/pipeline/merging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ func TestMerging__getCanceledFiles(t *testing.T) {
dir := filepath.Join(root, "test-2024")
require.NoError(t, os.MkdirAll(dir, 0777))

name1 := fmt.Sprintf("%s.ach", base.ID())
name1 := base.ID() + ".ach"
xfer1 := write(t, filepath.Join(dir, name1), nil)
write(t, filepath.Join(dir, fmt.Sprintf("%s.canceled", xfer1)), nil)
write(t, filepath.Join(dir, xfer1+".canceled"), nil)

name2 := fmt.Sprintf("%s.ach", base.ID())
name2 := base.ID() + ".ach"
write(t, filepath.Join(dir, name2), nil)

name3 := fmt.Sprintf("%s.ach", base.ID())
write(t, filepath.Join(dir, fmt.Sprintf("%s.canceled", name3)), nil)
name3 := base.ID() + ".ach"
write(t, filepath.Join(dir, name3+".canceled"), nil)

fs, err := storage.NewFilesystem(root)
require.NoError(t, err)
Expand All @@ -76,12 +76,12 @@ func TestMerging__getNonCanceledMatches(t *testing.T) {
dir := filepath.Join(root, "test-2021")
require.NoError(t, os.Mkdir(dir, 0777))

xfer1 := write(t, filepath.Join(dir, fmt.Sprintf("%s.ach", base.ID())), nil)
xfer1 := write(t, filepath.Join(dir, base.ID()+".ach"), nil)

cancel1 := write(t, filepath.Join(dir, fmt.Sprintf("%s.ach.canceled", base.ID())), nil)
cancel1 := write(t, filepath.Join(dir, base.ID()+".ach.canceled"), nil)

xfer2 := write(t, filepath.Join(dir, fmt.Sprintf("%s.ach", base.ID())), nil)
cancel2 := write(t, filepath.Join(dir, fmt.Sprintf("%s.canceled", xfer2)), nil)
xfer2 := write(t, filepath.Join(dir, base.ID()+".ach"), nil)
cancel2 := write(t, filepath.Join(dir, xfer2+".canceled"), nil)

fs, err := storage.NewFilesystem(root)
require.NoError(t, err)
Expand Down Expand Up @@ -122,9 +122,9 @@ func write(t *testing.T, where string, contents []byte) string {
}

func TestMerging_fileAcceptor(t *testing.T) {
name1 := fmt.Sprintf("%s.ach", base.ID())
name2 := fmt.Sprintf("%s.ach", base.ID())
json1 := fmt.Sprintf("%s.json", base.ID())
name1 := base.ID() + ".ach"
name2 := base.ID() + ".ach"
json1 := base.ID() + ".json"

output := fileAcceptor(nil)(name1)
require.Equal(t, ach.AcceptFile, output)
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestMerging_mappings(t *testing.T) {
expected := []string{"duplicate-trace.ach", "ppd-debit.ach", "ppd-debit2.ach", "ppd-debit3.ach", "ppd-debit4.ach"}
require.ElementsMatch(t, expected, mapped[0].InputFilepaths)
require.Equal(t, "MAPPING-0.ach", mapped[0].UploadedFilename)
require.Equal(t, 2, len(mapped[0].ACHFile.Batches))
require.Len(t, mapped[0].ACHFile.Batches, 2)
}

func enqueueFile(t *testing.T, merging XferMerging, path string) {
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestMerging__writeACHFile(t *testing.T) {

// Verify the .ach and .json files were written
mergableFilenames := getFilenames(t, m.storage, "mergable/testing")
expected := []string{fmt.Sprintf("%s.ach", fileID), fmt.Sprintf("%s.json", fileID)}
expected := []string{fileID + ".ach", fileID + ".json"}
require.ElementsMatch(t, expected, mergableFilenames)

var mergeConditions ach.Conditions
Expand Down
2 changes: 1 addition & 1 deletion internal/schedule/cutoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (ct *CutoffTimes) register(tz string, timestamp string) error {
var zone string
var location *time.Location
if tz != "" {
zone = fmt.Sprintf("CRON_TZ=%s", tz)
zone = "CRON_TZ=" + tz
l, _ := time.LoadLocation(tz)
location = l
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func bootAdminServer(errs chan<- error, logger log.Logger, config service.Admin)
}

go func() {
logger.Info().Log(fmt.Sprintf("listening on %s", adminServer.BindAddr()))
logger.Info().Log("listening on " + adminServer.BindAddr())
if err := adminServer.Listen(); err != nil {
errs <- logger.Fatal().LogErrorf("problem starting admin http: %w", err).Err()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Test_ConfigLoading(t *testing.T) {

gc := &service.GlobalConfig{}
err := ConfigService.Load(gc)
require.Nil(t, err)
require.NoError(t, err)

// Validate config
require.NoError(t, gc.ACHGateway.Validate())
Expand Down
2 changes: 1 addition & 1 deletion internal/service/model_audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ func TestSignerMasking(t *testing.T) {
cfg := &Signer{KeyFile: "/foo.pem", KeyPassword: "secret"}
bs, err := json.Marshal(cfg)
require.NoError(t, err)
require.Equal(t, bs, []byte(`{"KeyFile":"/foo.pem","KeyPassword":"s****t"}`))
require.JSONEq(t, string(bs), `{"KeyFile":"/foo.pem","KeyPassword":"s****t"}`)
}
5 changes: 2 additions & 3 deletions internal/service/model_upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package service

import (
"encoding/json"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -29,12 +28,12 @@ func TestFTPMasking(t *testing.T) {
cfg := &FTP{Password: "secret"}
bs, err := json.Marshal(cfg)
require.NoError(t, err)
require.True(t, strings.Contains(string(bs), `,"Password":"s****t",`))
require.Contains(t, string(bs), `,"Password":"s****t",`)
}

func TestSFTPMasking(t *testing.T) {
cfg := &SFTP{Password: "secret"}
bs, err := json.Marshal(cfg)
require.NoError(t, err)
require.True(t, strings.Contains(string(bs), `,"Password":"s****t",`))
require.Contains(t, string(bs), `,"Password":"s****t",`)
}
3 changes: 1 addition & 2 deletions internal/shards/api_shard_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package shards_test

import (
"fmt"
"github.com/moov-io/achgateway/internal/service"
"net/http"
"testing"
Expand Down Expand Up @@ -74,7 +73,7 @@ func clientShardMappingCreate(s ShardMappingTestScope, create *service.ShardMapp

func clientShardMappingGet(s ShardMappingTestScope, shardKey string) (*service.ShardMapping, *http.Response) {
i := &service.ShardMapping{}
resp := s.MakeCall(s.MakeRequest("GET", fmt.Sprintf("/shard_mappings/%s", shardKey), nil), i)
resp := s.MakeCall(s.MakeRequest("GET", "/shard_mappings/"+shardKey, nil), i)
return i, resp
}

Expand Down
2 changes: 1 addition & 1 deletion internal/shards/service_shard_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestFacilitatorService_List(t *testing.T) {

list, err := s.Service.List()
require.NoError(t, err)
require.Equal(t, 3, len(list))
require.Len(t, list, 3)
}

func TestFacilitatorService_Get(t *testing.T) {
Expand Down
Loading

0 comments on commit c3d677a

Please sign in to comment.