Skip to content

Commit 37c5713

Browse files
committed
Run go vet
1 parent ef870a3 commit 37c5713

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
})
@@ -293,15 +293,15 @@ func (poll *Poll) GetResult(ctx context.Context) ([]map[string]int, error) {
293293
pollResult := make(map[string]int)
294294
cursor, err := Client.Database(db).Collection("votes").Aggregate(ctx, mongo.Pipeline{
295295
{{
296-
"$match", bson.D{
297-
{"pollId", pollId},
296+
Key: "$match", Value: bson.D{
297+
{Key: "pollId", Value: pollId},
298298
},
299299
}},
300300
{{
301-
"$group", bson.D{
302-
{"_id", "$option"},
303-
{"count", bson.D{
304-
{"$sum", 1},
301+
Key: "$group", Value: bson.D{
302+
{Key: "_id", Value: "$option"},
303+
{Key: "count", Value: bson.D{
304+
{Key: "$sum", Value: 1},
305305
}},
306306
},
307307
}},
@@ -328,8 +328,8 @@ func (poll *Poll) GetResult(ctx context.Context) ([]map[string]int, error) {
328328
// Get all votes
329329
cursor, err := Client.Database(db).Collection("votes").Aggregate(ctx, mongo.Pipeline{
330330
{{
331-
"$match", bson.D{
332-
{"pollId", pollId},
331+
Key: "$match", Value: bson.D{
332+
{Key: "pollId", Value: pollId},
333333
},
334334
}},
335335
})

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)