Skip to content

Commit a0251fa

Browse files
Minor code fixes based on golangci
1 parent e073603 commit a0251fa

File tree

9 files changed

+25
-16
lines changed

9 files changed

+25
-16
lines changed

aggregate/repository_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/hellofresh/goengine/mocks"
1616
"github.com/stretchr/testify/assert"
1717
"github.com/stretchr/testify/mock"
18+
"github.com/stretchr/testify/require"
1819
)
1920

2021
func TestNewRepository(t *testing.T) {
@@ -103,7 +104,9 @@ func TestRepository_SaveAggregateRoot(t *testing.T) {
103104
{order: 2},
104105
}
105106
for _, event := range events {
106-
aggregate.RecordChange(root, event)
107+
require.NoError(t,
108+
aggregate.RecordChange(root, event),
109+
)
107110
}
108111
err := repo.SaveAggregateRoot(context.Background(), root)
109112

driver/sql/postgres/eventstore.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewEventStore(
5757
logger = goengine.NopLogger
5858
}
5959

60-
columns := fmt.Sprintf("%s", strings.Join(persistenceStrategy.ColumnNames(), ", "))
60+
columns := strings.Join(persistenceStrategy.ColumnNames(), ", ")
6161

6262
return &EventStore{
6363
persistenceStrategy: persistenceStrategy,
@@ -169,6 +169,7 @@ func (e *EventStore) loadQuery(
169169

170170
rows, err := db.QueryContext(
171171
ctx,
172+
/* #nosec */
172173
fmt.Sprintf(
173174
`SELECT * FROM %s WHERE %s ORDER BY no %s`,
174175
tableName,
@@ -206,6 +207,7 @@ func (e *EventStore) AppendToWithExecer(ctx context.Context, conn driverSQL.Exec
206207

207208
result, err := conn.ExecContext(
208209
ctx,
210+
/* #nosec */
209211
fmt.Sprintf(
210212
"INSERT INTO %s (%s) VALUES %s",
211213
tableName,

driver/sql/postgres/projector_aggregate_storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func newAggregateProjectionStorage(
114114
}, nil
115115
}
116116

117-
func (a *aggregateProjectionStorage) LoadOutOfSync(ctx context.Context, conn *sql.Conn) (*sql.Rows, error) {
117+
func (a *aggregateProjectionStorage) LoadOutOfSync(ctx context.Context, conn driverSQL.Queryer) (*sql.Rows, error) {
118118
return conn.QueryContext(ctx, a.queryOutOfSyncProjections)
119119
}
120120

@@ -136,7 +136,7 @@ func (a *aggregateProjectionStorage) PersistState(conn *sql.Conn, notification *
136136
return nil
137137
}
138138

139-
func (a *aggregateProjectionStorage) PersistFailure(ctx context.Context, conn *sql.Conn, notification *driverSQL.ProjectionNotification) error {
139+
func (a *aggregateProjectionStorage) PersistFailure(ctx context.Context, conn driverSQL.Execer, notification *driverSQL.ProjectionNotification) error {
140140
if _, err := conn.ExecContext(ctx, a.queryPersistFailure, notification.AggregateID); err != nil {
141141
return err
142142
}

driver/sql/postgres/projector_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ package postgres
44

55
import (
66
"fmt"
7+
"testing"
8+
79
"github.com/hellofresh/goengine"
810
"github.com/stretchr/testify/assert"
9-
"testing"
1011
)
1112

1213
func TestDefaultProjectionStateEncoder(t *testing.T) {

message.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ type (
3333

3434
// GenerateUUID creates a new random UUID or panics
3535
func GenerateUUID() UUID {
36-
37-
return UUID(uuid.New())
36+
return uuid.New()
3837
}
3938

4039
// IsUUIDEmpty returns true if the UUID is empty

metadata/matcher_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ func TestMatcherIterate(t *testing.T) {
8686

8787
for _, testCase := range testCases {
8888
t.Run("multiple constraints", func(t *testing.T) {
89-
var m metadata.Matcher
90-
m = testCase.matcher
91-
89+
m := testCase.matcher
9290
for _, c := range testCase.expectedConstraints {
9391
m = metadata.WithConstraint(m, c.field, c.operator, c.value)
9492
}

strategy/json/sql/postgres/single_stream_strategy_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ func TestColumnNames(t *testing.T) {
150150
})
151151

152152
t.Run("cannot modify data", func(t *testing.T) {
153-
colsOrig := strategy.ColumnNames()
154-
colsOrig = append(colsOrig, "field1")
155-
colsOrig = append(colsOrig, "field2")
156-
157153
assert.Equal(t, strategy.ColumnNames(), expectedColumns)
158154
})
159155
}

strategy/json/sql/postgres/sql_schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ $$;`
2727
// sqlTriggerEventStreamNotify a helper to create the sql on a event store table
2828
func sqlTriggerEventStreamNotifyTemplate(eventStreamName goengine.StreamName, eventStreamTable string) string {
2929
triggerName := fmt.Sprintf("%s_notify", eventStreamTable)
30+
/* #nosec */
3031
return fmt.Sprintf(
3132
`DO LANGUAGE plpgsql $$
3233
BEGIN
@@ -57,6 +58,7 @@ func sqlTriggerEventStreamNotifyTemplate(eventStreamName goengine.StreamName, ev
5758

5859
// StreamProjectorCreateSchema return the sql statement needed for the postgres database in order to use the StreamProjector
5960
func StreamProjectorCreateSchema(projectionTable string, streamName goengine.StreamName, streamTable string) []string {
61+
/* #nosec */
6062
return []string{
6163
sqlFuncEventStreamNotify,
6264
sqlTriggerEventStreamNotifyTemplate(streamName, streamTable),
@@ -77,6 +79,7 @@ func StreamProjectorCreateSchema(projectionTable string, streamName goengine.Str
7779

7880
// AggregateProjectorCreateSchema return the sql statement needed for the postgres database in order to use the AggregateProjector
7981
func AggregateProjectorCreateSchema(projectionTable string, streamName goengine.StreamName, streamTable string) []string {
82+
/* #nosec */
8083
return []string{
8184
sqlFuncEventStreamNotify,
8285
sqlTriggerEventStreamNotifyTemplate(streamName, streamTable),

test/internal/postgres.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,23 @@ func (c *dbController) Create(t *testing.T, databaseName string) {
6666
func (c *dbController) disableDatabaseAccess(t *testing.T, databaseName string) {
6767
// Making sure the database exists
6868
row := c.db.QueryRow("SELECT datname FROM pg_database WHERE datname = $1", databaseName)
69-
if row == nil {
69+
if err := row.Scan(&databaseName); err != nil {
7070
// No database so no one has access
71+
if err != sql.ErrNoRows {
72+
return
73+
}
74+
require.NoError(t, err)
7175
return
7276
}
77+
7378
// Disallow new connections
7479
_, err := c.db.Exec(fmt.Sprintf(`ALTER DATABASE "%s" WITH ALLOW_CONNECTIONS false`, databaseName))
7580
require.NoError(t, err, "test.postgres: Unable to disallow connections to the db")
7681

7782
// Terminate existing connections
78-
row = c.db.QueryRow("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = $1", databaseName)
83+
rows, err := c.db.Query("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = $1", databaseName)
84+
require.NoError(t, err)
85+
defer rows.Close()
7986
}
8087

8188
func (c *dbController) enableDatabaseAccess(t *testing.T, databaseName string) {

0 commit comments

Comments
 (0)