Skip to content

Commit

Permalink
Update Makefile to run examples and fix bugs in examples.
Browse files Browse the repository at this point in the history
GODRIVER-787
GODRIVER-768

Change-Id: I6bc92ef60fbc24d6224c40a99e24bc8cd9240107
  • Loading branch information
Divjot Arora committed Jan 31, 2019
1 parent 06b083e commit 0cb0bd0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
1 change: 1 addition & 0 deletions .lint-whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ bson/internal/jsonparser/parser.go:1137:9: if block ends with a return statement
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)
bson/internal/jsonparser/parser_test.go:1361:5: var testJson should be testJSON
bson/internal/jsonpretty/pretty.go:7:1: comment on exported type Options should be of the form "Options ..." (with optional leading article)
examples/documentation_examples/examples.go:10:1: don't use an underscore in package name
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ UNSTABLE_PKGS = $(shell etc/list_pkgs.sh ./x)
UNSTABLE_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./x)
TAG_PKG = $(shell etc/list_pkgs.sh ./tag)
TAG_TEST_PKG = $(shell etc/list_test_pkgs.sh ./tag)
PKGS = $(BSON_PKGS) $(MONGO_PKGS) $(UNSTABLE_PKGS) $(TAG_PKG)
TEST_PKGS = $(BSON_TEST_PKGS) $(MONGO_TEST_PKGS) $(UNSTABLE_TEST_PKGS) $(TAG_PKG)
EXAMPLES_PKGS = $(shell etc/list_pkgs.sh ./examples)
EXAMPLES_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./examples)
PKGS = $(BSON_PKGS) $(MONGO_PKGS) $(UNSTABLE_PKGS) $(TAG_PKG) $(EXAMPLES_PKGS)
TEST_PKGS = $(BSON_TEST_PKGS) $(MONGO_TEST_PKGS) $(UNSTABLE_TEST_PKGS) $(TAG_PKG) $(EXAMPLES_TEST_PKGS)

TEST_TIMEOUT = 600

Expand Down
49 changes: 22 additions & 27 deletions examples/documentation_examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ func requireCursorLength(t *testing.T, cursor mongo.Cursor, length int) {
require.Equal(t, i, length)
}

func stringSliceEquals(s1 []string, s2 []string) bool {
if len(s1) != len(s2) {
return false
}

for i := range s1 {
if s1[i] != s2[i] {
return false
}
}

return true
}

func containsKey(doc bsonx.Doc, key ...string) bool {
_, err := doc.LookupErr(key...)
if err != nil {
Expand All @@ -53,6 +39,7 @@ func containsKey(doc bsonx.Doc, key ...string) bool {
return true
}

// InsertExamples contains examples for insert operations.
func InsertExamples(t *testing.T, db *mongo.Database) {
err := db.RunCommand(
context.Background(),
Expand Down Expand Up @@ -144,6 +131,7 @@ func InsertExamples(t *testing.T, db *mongo.Database) {
}
}

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

}

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

}

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

}

// QueryArrayEmbeddedDocumentsExamples contains examples for querying fields with arrays and embedded documents.
func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
err := db.RunCommand(
context.Background(),
Expand Down Expand Up @@ -896,6 +887,7 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
}
}

// QueryNullMissingFieldsExamples contains examples for querying fields that are null or missing.
func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) {
err := db.RunCommand(
context.Background(),
Expand Down Expand Up @@ -976,6 +968,7 @@ func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) {
}
}

// ProjectionExamples contains examples for specifying projections in find operations.
func ProjectionExamples(t *testing.T, db *mongo.Database) {
err := db.RunCommand(
context.Background(),
Expand Down Expand Up @@ -1115,7 +1108,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

require.True(t, containsKey(doc, "_id"))
Expand Down Expand Up @@ -1152,7 +1145,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

require.False(t, containsKey(doc, "_id"))
Expand Down Expand Up @@ -1188,7 +1181,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

require.True(t, containsKey(doc, "_id"))
Expand Down Expand Up @@ -1225,7 +1218,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

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

require.True(t, containsKey(doc, "uom", "size"))
require.True(t, containsKey(doc, "size", "uom"))
require.False(t, containsKey(doc, "h", "size"))
require.False(t, containsKey(doc, "w", "size"))

Expand Down Expand Up @@ -1265,7 +1258,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

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

require.False(t, containsKey(doc, "uom", "size"))
require.True(t, containsKey(doc, "h", "size"))
require.True(t, containsKey(doc, "w", "size"))
require.True(t, containsKey(doc, "size", "h"))
require.True(t, containsKey(doc, "size", "w"))

}

Expand Down Expand Up @@ -1307,7 +1300,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

require.True(t, containsKey(doc, "_id"))
Expand Down Expand Up @@ -1360,7 +1353,7 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

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

// UpdateExamples contains examples of update operations.
func UpdateExamples(t *testing.T, db *mongo.Database) {
err := db.RunCommand(
context.Background(),
Expand Down Expand Up @@ -1537,7 +1531,7 @@ func UpdateExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

uom, err := doc.LookupErr("size", "uom")
Expand Down Expand Up @@ -1594,7 +1588,7 @@ func UpdateExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

uom, err := doc.LookupErr("size", "uom")
Expand Down Expand Up @@ -1651,7 +1645,7 @@ func UpdateExamples(t *testing.T, db *mongo.Database) {
doc := bsonx.Doc{}
for cursor.Next(context.Background()) {
doc = doc[:0]
err := cursor.Decode(doc)
err := cursor.Decode(&doc)
require.NoError(t, err)

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

}

// DeleteExamples contains examples of delete operations.
func DeleteExamples(t *testing.T, db *mongo.Database) {
err := db.RunCommand(
context.Background(),
Expand Down

0 comments on commit 0cb0bd0

Please sign in to comment.