Skip to content

Commit 02c16ac

Browse files
author
Christian Hergert
committed
tests: add database test case for failed command.
1 parent ca9f07c commit 02c16ac

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test-mongoc-database.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ test_command (void)
5858
mongoc_database_t *database;
5959
mongoc_client_t *client;
6060
mongoc_cursor_t *cursor;
61+
bson_error_t error;
6162
const bson_t *doc;
6263
bson_bool_t r;
6364
bson_t cmd = BSON_INITIALIZER;
65+
bson_t reply;
6466

6567
client = mongoc_client_new (gTestUri);
6668
assert (client);
6769

6870
database = mongoc_client_get_database (client, "admin");
6971

72+
/*
73+
* Test a known working command, "ping".
74+
*/
7075
bson_append_int32 (&cmd, "ping", 4, 1);
7176

7277
cursor = mongoc_database_command (database, MONGOC_QUERY_NONE, 0, 1, &cmd, NULL, NULL);
@@ -81,6 +86,20 @@ test_command (void)
8186
assert (!doc);
8287

8388
mongoc_cursor_destroy (cursor);
89+
90+
91+
/*
92+
* Test a non-existing command to ensure we get the failure.
93+
*/
94+
bson_reinit (&cmd);
95+
bson_append_int32 (&cmd, "a_non_existing_command", -1, 1);
96+
97+
r = mongoc_database_command_simple (database, &cmd, NULL, &reply, &error);
98+
assert (!r);
99+
assert (error.domain == MONGOC_ERROR_QUERY);
100+
assert (error.code == MONGOC_ERROR_QUERY_COMMAND_NOT_FOUND);
101+
assert (!strcmp ("no such cmd: a_non_existing_command", error.message));
102+
84103
mongoc_database_destroy (database);
85104
mongoc_client_destroy (client);
86105
bson_destroy (&cmd);

0 commit comments

Comments
 (0)