Skip to content

Commit 0cb0bd0

Browse files
author
Divjot Arora
committed
Update Makefile to run examples and fix bugs in examples.
GODRIVER-787 GODRIVER-768 Change-Id: I6bc92ef60fbc24d6224c40a99e24bc8cd9240107
1 parent 06b083e commit 0cb0bd0

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

.lint-whitelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ bson/internal/jsonparser/parser.go:1137:9: if block ends with a return statement
6161
bson/internal/jsonparser/parser.go:1146:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
6262
bson/internal/jsonparser/parser_test.go:1361:5: var testJson should be testJSON
6363
bson/internal/jsonpretty/pretty.go:7:1: comment on exported type Options should be of the form "Options ..." (with optional leading article)
64+
examples/documentation_examples/examples.go:10:1: don't use an underscore in package name

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ UNSTABLE_PKGS = $(shell etc/list_pkgs.sh ./x)
66
UNSTABLE_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./x)
77
TAG_PKG = $(shell etc/list_pkgs.sh ./tag)
88
TAG_TEST_PKG = $(shell etc/list_test_pkgs.sh ./tag)
9-
PKGS = $(BSON_PKGS) $(MONGO_PKGS) $(UNSTABLE_PKGS) $(TAG_PKG)
10-
TEST_PKGS = $(BSON_TEST_PKGS) $(MONGO_TEST_PKGS) $(UNSTABLE_TEST_PKGS) $(TAG_PKG)
9+
EXAMPLES_PKGS = $(shell etc/list_pkgs.sh ./examples)
10+
EXAMPLES_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./examples)
11+
PKGS = $(BSON_PKGS) $(MONGO_PKGS) $(UNSTABLE_PKGS) $(TAG_PKG) $(EXAMPLES_PKGS)
12+
TEST_PKGS = $(BSON_TEST_PKGS) $(MONGO_TEST_PKGS) $(UNSTABLE_TEST_PKGS) $(TAG_PKG) $(EXAMPLES_TEST_PKGS)
1113

1214
TEST_TIMEOUT = 600
1315

examples/documentation_examples/examples.go

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,6 @@ func requireCursorLength(t *testing.T, cursor mongo.Cursor, length int) {
3131
require.Equal(t, i, length)
3232
}
3333

34-
func stringSliceEquals(s1 []string, s2 []string) bool {
35-
if len(s1) != len(s2) {
36-
return false
37-
}
38-
39-
for i := range s1 {
40-
if s1[i] != s2[i] {
41-
return false
42-
}
43-
}
44-
45-
return true
46-
}
47-
4834
func containsKey(doc bsonx.Doc, key ...string) bool {
4935
_, err := doc.LookupErr(key...)
5036
if err != nil {
@@ -53,6 +39,7 @@ func containsKey(doc bsonx.Doc, key ...string) bool {
5339
return true
5440
}
5541

42+
// InsertExamples contains examples for insert operations.
5643
func InsertExamples(t *testing.T, db *mongo.Database) {
5744
err := db.RunCommand(
5845
context.Background(),
@@ -144,6 +131,7 @@ func InsertExamples(t *testing.T, db *mongo.Database) {
144131
}
145132
}
146133

134+
// QueryToplevelFieldsExamples contains examples for querying top-level fields.
147135
func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) {
148136
err := db.RunCommand(
149137
context.Background(),
@@ -314,6 +302,7 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) {
314302

315303
}
316304

305+
// QueryEmbeddedDocumentsExamples contains examples for querying embedded document fields.
317306
func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
318307
err := db.RunCommand(
319308
context.Background(),
@@ -477,6 +466,7 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
477466

478467
}
479468

469+
// QueryArraysExamples contains examples for querying array fields.
480470
func QueryArraysExamples(t *testing.T, db *mongo.Database) {
481471
err := db.RunCommand(
482472
context.Background(),
@@ -665,6 +655,7 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) {
665655

666656
}
667657

658+
// QueryArrayEmbeddedDocumentsExamples contains examples for querying fields with arrays and embedded documents.
668659
func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
669660
err := db.RunCommand(
670661
context.Background(),
@@ -896,6 +887,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
896887
}
897888
}
898889

890+
// QueryNullMissingFieldsExamples contains examples for querying fields that are null or missing.
899891
func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) {
900892
err := db.RunCommand(
901893
context.Background(),
@@ -976,6 +968,7 @@ func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) {
976968
}
977969
}
978970

971+
// ProjectionExamples contains examples for specifying projections in find operations.
979972
func ProjectionExamples(t *testing.T, db *mongo.Database) {
980973
err := db.RunCommand(
981974
context.Background(),
@@ -1115,7 +1108,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
11151108
doc := bsonx.Doc{}
11161109
for cursor.Next(context.Background()) {
11171110
doc = doc[:0]
1118-
err := cursor.Decode(doc)
1111+
err := cursor.Decode(&doc)
11191112
require.NoError(t, err)
11201113

11211114
require.True(t, containsKey(doc, "_id"))
@@ -1152,7 +1145,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
11521145
doc := bsonx.Doc{}
11531146
for cursor.Next(context.Background()) {
11541147
doc = doc[:0]
1155-
err := cursor.Decode(doc)
1148+
err := cursor.Decode(&doc)
11561149
require.NoError(t, err)
11571150

11581151
require.False(t, containsKey(doc, "_id"))
@@ -1188,7 +1181,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
11881181
doc := bsonx.Doc{}
11891182
for cursor.Next(context.Background()) {
11901183
doc = doc[:0]
1191-
err := cursor.Decode(doc)
1184+
err := cursor.Decode(&doc)
11921185
require.NoError(t, err)
11931186

11941187
require.True(t, containsKey(doc, "_id"))
@@ -1225,7 +1218,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
12251218
doc := bsonx.Doc{}
12261219
for cursor.Next(context.Background()) {
12271220
doc = doc[:0]
1228-
err := cursor.Decode(doc)
1221+
err := cursor.Decode(&doc)
12291222
require.NoError(t, err)
12301223

12311224
require.True(t, containsKey(doc, "_id"))
@@ -1234,7 +1227,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
12341227
require.True(t, containsKey(doc, "size"))
12351228
require.False(t, containsKey(doc, "instock"))
12361229

1237-
require.True(t, containsKey(doc, "uom", "size"))
1230+
require.True(t, containsKey(doc, "size", "uom"))
12381231
require.False(t, containsKey(doc, "h", "size"))
12391232
require.False(t, containsKey(doc, "w", "size"))
12401233

@@ -1265,7 +1258,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
12651258
doc := bsonx.Doc{}
12661259
for cursor.Next(context.Background()) {
12671260
doc = doc[:0]
1268-
err := cursor.Decode(doc)
1261+
err := cursor.Decode(&doc)
12691262
require.NoError(t, err)
12701263

12711264
require.True(t, containsKey(doc, "_id"))
@@ -1275,8 +1268,8 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
12751268
require.True(t, containsKey(doc, "instock"))
12761269

12771270
require.False(t, containsKey(doc, "uom", "size"))
1278-
require.True(t, containsKey(doc, "h", "size"))
1279-
require.True(t, containsKey(doc, "w", "size"))
1271+
require.True(t, containsKey(doc, "size", "h"))
1272+
require.True(t, containsKey(doc, "size", "w"))
12801273

12811274
}
12821275

@@ -1307,7 +1300,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
13071300
doc := bsonx.Doc{}
13081301
for cursor.Next(context.Background()) {
13091302
doc = doc[:0]
1310-
err := cursor.Decode(doc)
1303+
err := cursor.Decode(&doc)
13111304
require.NoError(t, err)
13121305

13131306
require.True(t, containsKey(doc, "_id"))
@@ -1360,7 +1353,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
13601353
doc := bsonx.Doc{}
13611354
for cursor.Next(context.Background()) {
13621355
doc = doc[:0]
1363-
err := cursor.Decode(doc)
1356+
err := cursor.Decode(&doc)
13641357
require.NoError(t, err)
13651358

13661359
require.True(t, containsKey(doc, "_id"))
@@ -1378,6 +1371,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
13781371
}
13791372
}
13801373

1374+
// UpdateExamples contains examples of update operations.
13811375
func UpdateExamples(t *testing.T, db *mongo.Database) {
13821376
err := db.RunCommand(
13831377
context.Background(),
@@ -1537,7 +1531,7 @@ func UpdateExamples(t *testing.T, db *mongo.Database) {
15371531
doc := bsonx.Doc{}
15381532
for cursor.Next(context.Background()) {
15391533
doc = doc[:0]
1540-
err := cursor.Decode(doc)
1534+
err := cursor.Decode(&doc)
15411535
require.NoError(t, err)
15421536

15431537
uom, err := doc.LookupErr("size", "uom")
@@ -1594,7 +1588,7 @@ func UpdateExamples(t *testing.T, db *mongo.Database) {
15941588
doc := bsonx.Doc{}
15951589
for cursor.Next(context.Background()) {
15961590
doc = doc[:0]
1597-
err := cursor.Decode(doc)
1591+
err := cursor.Decode(&doc)
15981592
require.NoError(t, err)
15991593

16001594
uom, err := doc.LookupErr("size", "uom")
@@ -1651,7 +1645,7 @@ func UpdateExamples(t *testing.T, db *mongo.Database) {
16511645
doc := bsonx.Doc{}
16521646
for cursor.Next(context.Background()) {
16531647
doc = doc[:0]
1654-
err := cursor.Decode(doc)
1648+
err := cursor.Decode(&doc)
16551649
require.NoError(t, err)
16561650

16571651
require.True(t, containsKey(doc, "_id"))
@@ -1669,6 +1663,7 @@ func UpdateExamples(t *testing.T, db *mongo.Database) {
16691663

16701664
}
16711665

1666+
// DeleteExamples contains examples of delete operations.
16721667
func DeleteExamples(t *testing.T, db *mongo.Database) {
16731668
err := db.RunCommand(
16741669
context.Background(),

0 commit comments

Comments
 (0)