Skip to content

Commit a02aaea

Browse files
author
Isabella Siu
committed
GODRIVER-555 make Database.RunCommand return a *SingleResult
Change-Id: Ica6d147723772fddc89032264d9d6f4d48dcc914
1 parent 397cb6a commit a02aaea

20 files changed

+206
-172
lines changed

benchmark/multi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func multiInsertCase(ctx context.Context, tm TimerManager, iters int, data strin
109109
return err
110110
}
111111

112-
_, err = db.RunCommand(ctx, bsonx.Doc{{"create", bsonx.String("corpus")}})
112+
err = db.RunCommand(ctx, bsonx.Doc{{"create", bsonx.String("corpus")}}).Err()
113113
if err != nil {
114114
return err
115115
}

benchmark/single.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ func SingleRunCommand(ctx context.Context, tm TimerManager, iters int) error {
5353

5454
tm.ResetTimer()
5555
for i := 0; i < iters; i++ {
56-
out, err := db.RunCommand(ctx, cmd)
56+
var doc bsonx.Doc
57+
err := db.RunCommand(ctx, cmd).Decode(&doc)
5758
if err != nil {
5859
return err
5960
}
6061
// read the document and then throw it away to prevent
62+
out, err := doc.MarshalBSON()
6163
if len(out) == 0 {
6264
return errors.New("output of ismaster is empty")
6365
}
@@ -135,7 +137,7 @@ func singleInsertCase(ctx context.Context, tm TimerManager, iters int, data stri
135137
return err
136138
}
137139

138-
_, err = db.RunCommand(ctx, bsonx.Doc{{"create", bsonx.String("corpus")}})
140+
err = db.RunCommand(ctx, bsonx.Doc{{"create", bsonx.String("corpus")}}).Err()
139141
if err != nil {
140142
return err
141143
}

examples/documentation_examples/examples.go

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ func containsKey(doc bsonx.Doc, key ...string) bool {
5454
}
5555

5656
func InsertExamples(t *testing.T, db *mongo.Database) {
57-
_, err := db.RunCommand(
57+
err := db.RunCommand(
5858
context.Background(),
5959
bson.D{{"dropDatabase", 1}},
60-
)
60+
).Err()
6161
require.NoError(t, err)
6262

6363
coll := db.Collection("inventory")
@@ -145,10 +145,10 @@ func InsertExamples(t *testing.T, db *mongo.Database) {
145145
}
146146

147147
func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) {
148-
_, err := db.RunCommand(
148+
err := db.RunCommand(
149149
context.Background(),
150150
bson.D{{"dropDatabase", 1}},
151-
)
151+
).Err()
152152
require.NoError(t, err)
153153

154154
coll := db.Collection("inventory")
@@ -315,10 +315,10 @@ func QueryToplevelFieldsExamples(t *testing.T, db *mongo.Database) {
315315
}
316316

317317
func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
318-
_, err := db.RunCommand(
318+
err := db.RunCommand(
319319
context.Background(),
320320
bson.D{{"dropDatabase", 1}},
321-
)
321+
).Err()
322322
require.NoError(t, err)
323323

324324
coll := db.Collection("inventory")
@@ -478,10 +478,10 @@ func QueryEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
478478
}
479479

480480
func QueryArraysExamples(t *testing.T, db *mongo.Database) {
481-
_, err := db.RunCommand(
481+
err := db.RunCommand(
482482
context.Background(),
483483
bson.D{{"dropDatabase", 1}},
484-
)
484+
).Err()
485485
require.NoError(t, err)
486486

487487
coll := db.Collection("inventory")
@@ -666,10 +666,10 @@ func QueryArraysExamples(t *testing.T, db *mongo.Database) {
666666
}
667667

668668
func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
669-
_, err := db.RunCommand(
669+
err := db.RunCommand(
670670
context.Background(),
671671
bson.D{{"dropDatabase", 1}},
672-
)
672+
).Err()
673673
require.NoError(t, err)
674674

675675
coll := db.Collection("inventory")
@@ -897,10 +897,10 @@ func QueryArrayEmbeddedDocumentsExamples(t *testing.T, db *mongo.Database) {
897897
}
898898

899899
func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) {
900-
_, err := db.RunCommand(
900+
err := db.RunCommand(
901901
context.Background(),
902902
bson.D{{"dropDatabase", 1}},
903-
)
903+
).Err()
904904
require.NoError(t, err)
905905

906906
coll := db.Collection("inventory")
@@ -977,10 +977,10 @@ func QueryNullMissingFieldsExamples(t *testing.T, db *mongo.Database) {
977977
}
978978

979979
func ProjectionExamples(t *testing.T, db *mongo.Database) {
980-
_, err := db.RunCommand(
980+
err := db.RunCommand(
981981
context.Background(),
982982
bson.D{{"dropDatabase", 1}},
983-
)
983+
).Err()
984984
require.NoError(t, err)
985985

986986
coll := db.Collection("inventory")
@@ -1099,7 +1099,6 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
10991099
{"item", 1},
11001100
{"status", 1},
11011101
}
1102-
require.NoError(t, err)
11031102

11041103
cursor, err := coll.Find(
11051104
context.Background(),
@@ -1137,7 +1136,6 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
11371136
{"status", 1},
11381137
{"_id", 0},
11391138
}
1140-
require.NoError(t, err)
11411139

11421140
cursor, err := coll.Find(
11431141
context.Background(),
@@ -1174,7 +1172,6 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
11741172
{"status", 0},
11751173
{"instock", 0},
11761174
}
1177-
require.NoError(t, err)
11781175

11791176
cursor, err := coll.Find(
11801177
context.Background(),
@@ -1212,7 +1209,6 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
12121209
{"status", 1},
12131210
{"size.uom", 1},
12141211
}
1215-
require.NoError(t, err)
12161212

12171213
cursor, err := coll.Find(
12181214
context.Background(),
@@ -1253,7 +1249,6 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
12531249
projection := bson.D{
12541250
{"size.uom", 0},
12551251
}
1256-
require.NoError(t, err)
12571252

12581253
cursor, err := coll.Find(
12591254
context.Background(),
@@ -1296,7 +1291,6 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
12961291
{"status", 1},
12971292
{"instock.qty", 1},
12981293
}
1299-
require.NoError(t, err)
13001294

13011295
cursor, err := coll.Find(
13021296
context.Background(),
@@ -1350,7 +1344,6 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
13501344
{"$slice", -1},
13511345
}},
13521346
}
1353-
require.NoError(t, err)
13541347

13551348
cursor, err := coll.Find(
13561349
context.Background(),
@@ -1386,10 +1379,10 @@ func ProjectionExamples(t *testing.T, db *mongo.Database) {
13861379
}
13871380

13881381
func UpdateExamples(t *testing.T, db *mongo.Database) {
1389-
_, err := db.RunCommand(
1382+
err := db.RunCommand(
13901383
context.Background(),
13911384
bson.D{{"dropDatabase", 1}},
1392-
)
1385+
).Err()
13931386
require.NoError(t, err)
13941387

13951388
coll := db.Collection("inventory")
@@ -1677,10 +1670,10 @@ func UpdateExamples(t *testing.T, db *mongo.Database) {
16771670
}
16781671

16791672
func DeleteExamples(t *testing.T, db *mongo.Database) {
1680-
_, err := db.RunCommand(
1673+
err := db.RunCommand(
16811674
context.Background(),
16821675
bson.D{{"dropDatabase", 1}},
1683-
)
1676+
).Err()
16841677
require.NoError(t, err)
16851678

16861679
coll := db.Collection("inventory")

mongo/client_internal_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@ func TestClient_TLSConnection(t *testing.T) {
8888
c := createTestClient(t)
8989
db := c.Database("test")
9090

91-
result, err := db.RunCommand(context.Background(), bsonx.Doc{{"serverStatus", bsonx.Int32(1)}})
91+
var result bsonx.Doc
92+
err := db.RunCommand(context.Background(), bsonx.Doc{{"serverStatus", bsonx.Int32(1)}}).Decode(&result)
9293
require.NoError(t, err)
9394

9495
security, err := result.LookupErr("security")
9596
require.Nil(t, err)
9697

97-
require.Equal(t, security.Type, bson.TypeEmbeddedDocument)
98+
require.Equal(t, security.Type(), bson.TypeEmbeddedDocument)
9899

99100
_, found := security.Document().LookupErr("SSLServerSubjectName")
100101
require.Nil(t, found)
@@ -123,20 +124,20 @@ func TestClient_X509Auth(t *testing.T) {
123124
db := c.Database("$external")
124125

125126
// We don't care if the user doesn't already exist.
126-
_, _ = db.RunCommand(
127+
_ = db.RunCommand(
127128
context.Background(),
128129
bsonx.Doc{{"dropUser", bsonx.String(user)}},
129130
)
130131

131-
_, err := db.RunCommand(
132+
err := db.RunCommand(
132133
context.Background(),
133134
bsonx.Doc{
134135
{"createUser", bsonx.String(user)},
135136
{"roles", bsonx.Array(bsonx.Arr{bsonx.Document(
136137
bsonx.Doc{{"role", bsonx.String("readWrite")}, {"db", bsonx.String("test")}},
137138
)})},
138139
},
139-
)
140+
).Err()
140141
require.NoError(t, err)
141142

142143
basePath := path.Join("..", "data", "certificates")
@@ -154,10 +155,11 @@ func TestClient_X509Auth(t *testing.T) {
154155
require.NoError(t, err)
155156

156157
db = authClient.Database("test")
157-
rdr, err := db.RunCommand(
158+
var rdr bson.Raw
159+
rdr, err = db.RunCommand(
158160
context.Background(),
159161
bsonx.Doc{{"connectionStatus", bsonx.Int32(1)}},
160-
)
162+
).DecodeBytes()
161163
require.NoError(t, err)
162164

163165
users, err := rdr.LookupErr("authInfo", "authenticatedUsers")

0 commit comments

Comments
 (0)