Skip to content

Commit ef1ae68

Browse files
authored
Merge pull request #558 from cybertec-postgresql/fix-unused-code
[*] remove unused parameters and code
2 parents 5978568 + 55541ec commit ef1ae68

File tree

12 files changed

+31
-46
lines changed

12 files changed

+31
-46
lines changed

internal/api/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ func (r *apihandler) IsReady() bool {
2020
return true
2121
}
2222

23-
func (r *apihandler) StartChain(ctx context.Context, chainID int) error {
23+
func (r *apihandler) StartChain(_ context.Context, chainID int) error {
2424
if chainID == 0 {
2525
return errors.New("invalid chain id")
2626
}
2727
return nil
2828
}
2929

30-
func (r *apihandler) StopChain(ctx context.Context, chainID int) error {
30+
func (r *apihandler) StopChain(context.Context, int) error {
3131
return nil
3232
}
3333

internal/log/log_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestFileLogger(t *testing.T) {
3131
_ = os.Remove("test.log")
3232
}
3333

34-
func TestPgxLog(t *testing.T) {
34+
func TestPgxLog(*testing.T) {
3535
pgxl := log.NewPgxLogger(log.Init(config.LoggingOpts{LogLevel: "trace"}))
3636
var level tracelog.LogLevel
3737
for level = tracelog.LogLevelNone; level <= tracelog.LogLevelTrace; level++ {

internal/migrator/migrator_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ func migrateTest() error {
6161
return err
6262
}
6363
defer db.Release()
64-
if err := migrator.Migrate(ctx, db.Conn()); err != nil {
65-
return err
66-
}
67-
68-
return nil
64+
return migrator.Migrate(ctx, db.Conn())
6965
}
7066

7167
func mustMigrator(migrator *migrator.Migrator, err error) *migrator.Migrator {

internal/pgengine/migration.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ func (pge *PgEngine) MigrateDb(ctx context.Context) error {
2424
if err != nil {
2525
return err
2626
}
27-
if err := m.Migrate(ctx, conn.Conn()); err != nil {
28-
return err
29-
}
30-
return nil
27+
return m.Migrate(ctx, conn.Conn())
3128
}
3229

3330
// CheckNeedMigrateDb checks need of upgrading database and throws error if that's true

internal/pgengine/pgengine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestSchedulerFunctions(t *testing.T) {
143143
tx, txid, err := pge.StartTransaction(ctx, 0)
144144
assert.NoError(t, err, "Should start transaction")
145145
assert.Greater(t, txid, 0, "Should return transaction id")
146-
assert.NoError(t, pge.GetChainElements(ctx, tx, &chains, 0), "Should no error in clean database")
146+
assert.NoError(t, pge.GetChainElements(ctx, &chains, 0), "Should no error in clean database")
147147
assert.Empty(t, chains, "Should be empty in clean database")
148148
pge.CommitTransaction(ctx, tx)
149149
})
@@ -153,7 +153,7 @@ func TestSchedulerFunctions(t *testing.T) {
153153
tx, txid, err := pge.StartTransaction(ctx, 0)
154154
assert.NoError(t, err, "Should start transaction")
155155
assert.Greater(t, txid, 0, "Should return transaction id")
156-
assert.NoError(t, pge.GetChainParamValues(ctx, tx, &paramVals, &pgengine.ChainTask{
156+
assert.NoError(t, pge.GetChainParamValues(ctx, &paramVals, &pgengine.ChainTask{
157157
TaskID: 0,
158158
ChainID: 0}), "Should no error in clean database")
159159
assert.Empty(t, paramVals, "Should be empty in clean database")

internal/pgengine/transaction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (pge *PgEngine) MustRollbackToSavepoint(ctx context.Context, tx pgx.Tx, sav
108108
}
109109

110110
// GetChainElements returns all elements for a given chain
111-
func (pge *PgEngine) GetChainElements(ctx context.Context, tx pgx.Tx, chainTasks *[]ChainTask, chainID int) error {
111+
func (pge *PgEngine) GetChainElements(ctx context.Context, chainTasks *[]ChainTask, chainID int) error {
112112
const sqlSelectChainTasks = `SELECT task_id, command, kind, run_as, ignore_error, autonomous, database_connection, timeout
113113
FROM timetable.task WHERE chain_id = $1 ORDER BY task_order ASC`
114114
// return Select(ctx, tx, chainTasks, sqlSelectChainTasks, chainID)
@@ -121,7 +121,7 @@ FROM timetable.task WHERE chain_id = $1 ORDER BY task_order ASC`
121121
}
122122

123123
// GetChainParamValues returns parameter values to pass for task being executed
124-
func (pge *PgEngine) GetChainParamValues(ctx context.Context, tx pgx.Tx, paramValues *[]string, task *ChainTask) error {
124+
func (pge *PgEngine) GetChainParamValues(ctx context.Context, paramValues *[]string, task *ChainTask) error {
125125
const sqlGetParamValues = `SELECT value FROM timetable.parameter WHERE task_id = $1 AND value IS NOT NULL ORDER BY order_id ASC`
126126
// return Select(ctx, tx, paramValues, sqlGetParamValues, task.TaskID)
127127
rows, err := pge.ConfigDb.Query(ctx, sqlGetParamValues, task.TaskID)

internal/pgengine/transaction_test.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,32 +136,20 @@ func TestGetChainElements(t *testing.T) {
136136
pge := pgengine.NewDB(mockPool, "pgengine_unit_test")
137137
ctx := context.Background()
138138

139-
mockPool.ExpectBegin()
140139
mockPool.ExpectQuery("SELECT").WithArgs(0).WillReturnError(errors.New("error"))
141-
tx, err := mockPool.Begin(ctx)
142-
assert.NoError(t, err)
143-
assert.Error(t, pge.GetChainElements(ctx, tx, &[]pgengine.ChainTask{}, 0))
140+
assert.Error(t, pge.GetChainElements(ctx, &[]pgengine.ChainTask{}, 0))
144141

145-
mockPool.ExpectBegin()
146142
mockPool.ExpectQuery("SELECT").WithArgs(0).WillReturnRows(
147143
pgxmock.NewRows([]string{"task_id", "command", "kind", "run_as",
148144
"ignore_error", "autonomous", "database_connection", "timeout"}).
149145
AddRow(24, "foo", "sql", "user", false, false, "postgres://foo@boo/bar", 0))
150-
tx, err = mockPool.Begin(ctx)
151-
assert.NoError(t, err)
152-
assert.NoError(t, pge.GetChainElements(ctx, tx, &[]pgengine.ChainTask{}, 0))
146+
assert.NoError(t, pge.GetChainElements(ctx, &[]pgengine.ChainTask{}, 0))
153147

154-
mockPool.ExpectBegin()
155148
mockPool.ExpectQuery("SELECT").WithArgs(0).WillReturnError(errors.New("error"))
156-
tx, err = mockPool.Begin(ctx)
157-
assert.NoError(t, err)
158-
assert.Error(t, pge.GetChainParamValues(ctx, tx, &[]string{}, &pgengine.ChainTask{}))
149+
assert.Error(t, pge.GetChainParamValues(ctx, &[]string{}, &pgengine.ChainTask{}))
159150

160-
mockPool.ExpectBegin()
161151
mockPool.ExpectQuery("SELECT").WithArgs(0).WillReturnRows(pgxmock.NewRows([]string{"s"}).AddRow("foo"))
162-
tx, err = mockPool.Begin(ctx)
163-
assert.NoError(t, err)
164-
assert.NoError(t, pge.GetChainParamValues(ctx, tx, &[]string{}, &pgengine.ChainTask{}))
152+
assert.NoError(t, pge.GetChainParamValues(ctx, &[]string{}, &pgengine.ChainTask{}))
165153
}
166154

167155
func TestSetRole(t *testing.T) {

internal/scheduler/chain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (sch *Scheduler) executeChain(ctx context.Context, chain Chain) {
188188
}
189189
chainL = chainL.WithField("txid", txid)
190190

191-
err = sch.pgengine.GetChainElements(ctx, tx, &ChainTasks, chain.ChainID)
191+
err = sch.pgengine.GetChainElements(ctx, &ChainTasks, chain.ChainID)
192192
if err != nil {
193193
chainL.WithError(err).Error("Failed to retrieve chain elements")
194194
sch.pgengine.RollbackTransaction(ctx, tx)
@@ -236,7 +236,7 @@ func (sch *Scheduler) executeСhainElement(ctx context.Context, tx pgx.Tx, task
236236

237237
l := log.GetLogger(ctx)
238238

239-
err = sch.pgengine.GetChainParamValues(ctx, tx, &paramValues, task)
239+
err = sch.pgengine.GetChainParamValues(ctx, &paramValues, task)
240240
if err != nil {
241241
l.WithError(err).Error("cannot fetch parameters values for chain: ", err)
242242
return -1

internal/scheduler/chain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/stretchr/testify/assert"
1717
)
1818

19-
func TestSchedulerExclusiveLocking(t *testing.T) {
19+
func TestSchedulerExclusiveLocking(*testing.T) {
2020
sch := &Scheduler{exclusiveMutex: sync.RWMutex{}}
2121
sch.Lock(true)
2222
sch.Unlock(true)

internal/scheduler/shell_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
type testCommander struct{}
2020

2121
// overwrite CombinedOutput function of os/exec so only parameter syntax and return codes are checked...
22-
func (c testCommander) CombinedOutput(ctx context.Context, command string, args ...string) ([]byte, error) {
22+
func (c testCommander) CombinedOutput(_ context.Context, command string, args ...string) ([]byte, error) {
2323
if strings.HasPrefix(command, "ping") {
2424
return []byte(fmt.Sprint(command, args)), nil
2525
}

0 commit comments

Comments
 (0)