Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Commit aea24cc

Browse files
committed
go vet and golint fixes
1 parent 80217ac commit aea24cc

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

enqueue_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func TestEnqueueOnlyType(t *testing.T) {
99
c := openTestClient(t)
1010
defer truncateAndClose(c.pool)
1111

12-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
12+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
1313
t.Fatal(err)
1414
}
1515

@@ -41,17 +41,16 @@ func TestEnqueueOnlyType(t *testing.T) {
4141
t.Errorf("want ErrorCount=%d, got %d", want, j.ErrorCount)
4242
}
4343
if j.LastError.Valid {
44-
t.Errorf("want no LastError, got %s", j.LastError)
44+
t.Errorf("want no LastError, got %v", j.LastError)
4545
}
46-
4746
}
4847

4948
func TestEnqueueWithPriority(t *testing.T) {
5049
c := openTestClient(t)
5150
defer truncateAndClose(c.pool)
5251

5352
want := int16(99)
54-
if err := c.Enqueue(Job{Type: "MyJob", Priority: want}); err != nil {
53+
if err := c.Enqueue(&Job{Type: "MyJob", Priority: want}); err != nil {
5554
t.Fatal(err)
5655
}
5756

@@ -70,7 +69,7 @@ func TestEnqueueWithRunAt(t *testing.T) {
7069
defer truncateAndClose(c.pool)
7170

7271
want := time.Now().Add(2 * time.Minute)
73-
if err := c.Enqueue(Job{Type: "MyJob", RunAt: want}); err != nil {
72+
if err := c.Enqueue(&Job{Type: "MyJob", RunAt: want}); err != nil {
7473
t.Fatal(err)
7574
}
7675

@@ -91,7 +90,7 @@ func TestEnqueueWithArgs(t *testing.T) {
9190
defer truncateAndClose(c.pool)
9291

9392
want := `{"arg1":0, "arg2":"a string"}`
94-
if err := c.Enqueue(Job{Type: "MyJob", Args: []byte(want)}); err != nil {
93+
if err := c.Enqueue(&Job{Type: "MyJob", Args: []byte(want)}); err != nil {
9594
t.Fatal(err)
9695
}
9796

@@ -110,7 +109,7 @@ func TestEnqueueWithQueue(t *testing.T) {
110109
defer truncateAndClose(c.pool)
111110

112111
want := "special-work-queue"
113-
if err := c.Enqueue(Job{Type: "MyJob", Queue: want}); err != nil {
112+
if err := c.Enqueue(&Job{Type: "MyJob", Queue: want}); err != nil {
114113
t.Fatal(err)
115114
}
116115

@@ -128,7 +127,7 @@ func TestEnqueueWithEmptyType(t *testing.T) {
128127
c := openTestClient(t)
129128
defer truncateAndClose(c.pool)
130129

131-
if err := c.Enqueue(Job{Type: ""}); err != ErrMissingType {
130+
if err := c.Enqueue(&Job{Type: ""}); err != ErrMissingType {
132131
t.Fatalf("want ErrMissingType, got %v", err)
133132
}
134133
}
@@ -143,7 +142,7 @@ func TestEnqueueInTx(t *testing.T) {
143142
}
144143
defer tx.Rollback()
145144

146-
if err = c.EnqueueInTx(Job{Type: "MyJob"}, tx); err != nil {
145+
if err = c.EnqueueInTx(&Job{Type: "MyJob"}, tx); err != nil {
147146
t.Fatal(err)
148147
}
149148

que.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,25 @@ func (j *Job) Error(msg string) error {
118118
return nil
119119
}
120120

121-
// TODO: add a way to specify default queueing options
121+
// Client is a Que client that can add jobs to the queue and remove jobs from
122+
// the queue.
122123
type Client struct {
123124
pool *pgx.ConnPool
125+
126+
// TODO: add a way to specify default queueing options
124127
}
125128

129+
// NewClient creates a new Client that uses the pgx pool.
126130
func NewClient(pool *pgx.ConnPool) *Client {
127131
return &Client{pool: pool}
128132
}
129133

134+
// ErrMissingType is returned when you attempt to enqueue a job with no Type
135+
// specified.
130136
var ErrMissingType = errors.New("job type must be specified")
131137

132138
// Enqueue adds a job to the queue.
133-
func (c *Client) Enqueue(j Job) error {
139+
func (c *Client) Enqueue(j *Job) error {
134140
return execEnqueue(j, c.pool)
135141
}
136142

@@ -140,11 +146,11 @@ func (c *Client) Enqueue(j Job) error {
140146
//
141147
// It is the caller's responsibility to Commit or Rollback the transaction after
142148
// this function is called.
143-
func (c *Client) EnqueueInTx(j Job, tx *pgx.Tx) error {
149+
func (c *Client) EnqueueInTx(j *Job, tx *pgx.Tx) error {
144150
return execEnqueue(j, tx)
145151
}
146152

147-
func execEnqueue(j Job, q queryable) error {
153+
func execEnqueue(j *Job, q queryable) error {
148154
if j.Type == "" {
149155
return ErrMissingType
150156
}

work_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func TestLockJob(t *testing.T) {
99
c := openTestClient(t)
1010
defer truncateAndClose(c.pool)
1111

12-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
12+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
1313
t.Fatal(err)
1414
}
1515

@@ -49,7 +49,7 @@ func TestLockJob(t *testing.T) {
4949
t.Errorf("want ErrorCount=%d, got %d", want, j.ErrorCount)
5050
}
5151
if j.LastError.Valid {
52-
t.Errorf("want no LastError, got %s", j.LastError)
52+
t.Errorf("want no LastError, got %v", j.LastError)
5353
}
5454

5555
// check for advisory lock
@@ -78,7 +78,7 @@ func TestLockJobAlreadyLocked(t *testing.T) {
7878
c := openTestClient(t)
7979
defer truncateAndClose(c.pool)
8080

81-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
81+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
8282
t.Fatal(err)
8383
}
8484

@@ -118,7 +118,7 @@ func TestLockJobCustomQueue(t *testing.T) {
118118
c := openTestClient(t)
119119
defer truncateAndClose(c.pool)
120120

121-
if err := c.Enqueue(Job{Type: "MyJob", Queue: "extra_priority"}); err != nil {
121+
if err := c.Enqueue(&Job{Type: "MyJob", Queue: "extra_priority"}); err != nil {
122122
t.Fatal(err)
123123
}
124124

@@ -150,7 +150,7 @@ func TestJobConn(t *testing.T) {
150150
c := openTestClient(t)
151151
defer truncateAndClose(c.pool)
152152

153-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
153+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
154154
t.Fatal(err)
155155
}
156156

@@ -172,7 +172,7 @@ func TestJobConnRace(t *testing.T) {
172172
c := openTestClient(t)
173173
defer truncateAndClose(c.pool)
174174

175-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
175+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
176176
t.Fatal(err)
177177
}
178178

@@ -205,7 +205,7 @@ func TestJobDelete(t *testing.T) {
205205
c := openTestClient(t)
206206
defer truncateAndClose(c.pool)
207207

208-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
208+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
209209
t.Fatal(err)
210210
}
211211

@@ -236,7 +236,7 @@ func TestJobDone(t *testing.T) {
236236
c := openTestClient(t)
237237
defer truncateAndClose(c.pool)
238238

239-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
239+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
240240
t.Fatal(err)
241241
}
242242

@@ -280,7 +280,7 @@ func TestJobDoneMultiple(t *testing.T) {
280280
c := openTestClient(t)
281281
defer truncateAndClose(c.pool)
282282

283-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
283+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
284284
t.Fatal(err)
285285
}
286286

@@ -301,7 +301,7 @@ func TestJobDeleteFromTx(t *testing.T) {
301301
c := openTestClient(t)
302302
defer truncateAndClose(c.pool)
303303

304-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
304+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
305305
t.Fatal(err)
306306
}
307307

@@ -352,7 +352,7 @@ func TestJobDeleteFromTxRollback(t *testing.T) {
352352
c := openTestClient(t)
353353
defer truncateAndClose(c.pool)
354354

355-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
355+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
356356
t.Fatal(err)
357357
}
358358

@@ -403,7 +403,7 @@ func TestJobError(t *testing.T) {
403403
c := openTestClient(t)
404404
defer truncateAndClose(c.pool)
405405

406-
if err := c.Enqueue(Job{Type: "MyJob"}); err != nil {
406+
if err := c.Enqueue(&Job{Type: "MyJob"}); err != nil {
407407
t.Fatal(err)
408408
}
409409

0 commit comments

Comments
 (0)