Skip to content

Commit f510452

Browse files
committed
Run go vet
1 parent 884da23 commit f510452

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

.github/workflows/go.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ jobs:
3232
- name: Run Tests
3333
run: |
3434
go test ./database
35+
- name: Run vet
36+
run: |
37+
go vet ./database/ ./logging/ ./sse/
38+
go vet *.go

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ gofmt -w -s *.go logging sse database
4545
4646
# run tests (database is the first place we've defined tests)
4747
go test ./database
48+
49+
# run heuristic validation
50+
go vet ./database/ ./logging/ ./sse/
51+
go vet *.go
4852
```
4953

5054
## To-Dos

database/poll.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,32 +143,32 @@ func GetClosedVotedPolls(ctx context.Context, userId string) ([]*Poll, error) {
143143

144144
cursor, err := Client.Database(db).Collection("votes").Aggregate(ctx, mongo.Pipeline{
145145
{{
146-
"$match", bson.D{
147-
{"userId", userId},
146+
Key: "$match", Value: bson.D{
147+
{Key: "userId", Value: userId},
148148
},
149149
}},
150150
{{
151-
"$lookup", bson.D{
152-
{"from", "polls"},
153-
{"localField", "pollId"},
154-
{"foreignField", "_id"},
155-
{"as", "polls"},
151+
Key: "$lookup", Value: bson.D{
152+
{Key: "from", Value: "polls"},
153+
{Key: "localField", Value: "pollId"},
154+
{Key: "foreignField", Value: "_id"},
155+
{Key: "as", Value: "polls"},
156156
},
157157
}},
158158
{{
159-
"$unwind", bson.D{
160-
{"path", "$polls"},
161-
{"preserveNullAndEmptyArrays", false},
159+
Key: "$unwind", Value: bson.D{
160+
{Key: "path", Value: "$polls"},
161+
{Key: "preserveNullAndEmptyArrays", Value: false},
162162
},
163163
}},
164164
{{
165-
"$replaceRoot", bson.D{
166-
{"newRoot", "$polls"},
165+
Key: "$replaceRoot", Value: bson.D{
166+
{Key: "newRoot", Value: "$polls"},
167167
},
168168
}},
169169
{{
170-
"$match", bson.D{
171-
{"open", false},
170+
Key: "$match", Value: bson.D{
171+
{Key: "open", Value: false},
172172
},
173173
}},
174174
})
@@ -294,15 +294,15 @@ func (poll *Poll) GetResult(ctx context.Context) ([]map[string]int, error) {
294294
pollResult := make(map[string]int)
295295
cursor, err := Client.Database(db).Collection("votes").Aggregate(ctx, mongo.Pipeline{
296296
{{
297-
"$match", bson.D{
298-
{"pollId", pollId},
297+
Key: "$match", Value: bson.D{
298+
{Key: "pollId", Value: pollId},
299299
},
300300
}},
301301
{{
302-
"$group", bson.D{
303-
{"_id", "$option"},
304-
{"count", bson.D{
305-
{"$sum", 1},
302+
Key: "$group", Value: bson.D{
303+
{Key: "_id", Value: "$option"},
304+
{Key: "count", Value: bson.D{
305+
{Key: "$sum", Value: 1},
306306
}},
307307
},
308308
}},
@@ -329,8 +329,8 @@ func (poll *Poll) GetResult(ctx context.Context) ([]map[string]int, error) {
329329
// Get all votes
330330
cursor, err := Client.Database(db).Collection("votes").Aggregate(ctx, mongo.Pipeline{
331331
{{
332-
"$match", bson.D{
333-
{"pollId", pollId},
332+
Key: "$match", Value: bson.D{
333+
{Key: "pollId", Value: pollId},
334334
},
335335
}},
336336
})

database/poll_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ func TestOrderOptions(t *testing.T) {
217217

218218
for _, test := range tests {
219219
t.Run(test.name, func(t *testing.T) {
220-
ctx, _ := context.WithTimeout(context.Background(), time.Second)
220+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
221+
defer cancel()
221222
assert.Equal(t, test.output, orderOptions(ctx, test.input))
222223
})
223224
}

0 commit comments

Comments
 (0)