|
1 | 1 | #include <mongoc.h>
|
| 2 | +#include <mongoc-collection-private.h> |
| 3 | +#include <mongoc-write-concern-private.h> |
| 4 | +#include <mongoc-read-concern-private.h> |
2 | 5 |
|
3 | 6 | #include "TestSuite.h"
|
4 | 7 | #include "test-libmongoc.h"
|
@@ -303,6 +306,46 @@ test_get_collection_info (void)
|
303 | 306 | mongoc_client_destroy (client);
|
304 | 307 | }
|
305 | 308 |
|
| 309 | +static void |
| 310 | +test_get_collection (void) |
| 311 | +{ |
| 312 | + mongoc_client_t *client; |
| 313 | + mongoc_database_t *database; |
| 314 | + mongoc_write_concern_t *wc; |
| 315 | + mongoc_read_concern_t *rc; |
| 316 | + mongoc_read_prefs_t *read_prefs; |
| 317 | + mongoc_collection_t *collection; |
| 318 | + |
| 319 | + client = test_framework_client_new (); |
| 320 | + assert (client); |
| 321 | + |
| 322 | + database = mongoc_client_get_database (client, "test"); |
| 323 | + |
| 324 | + wc = mongoc_write_concern_new (); |
| 325 | + mongoc_write_concern_set_w (wc, 2); |
| 326 | + mongoc_database_set_write_concern (database, wc); |
| 327 | + |
| 328 | + rc = mongoc_read_concern_new (); |
| 329 | + mongoc_read_concern_set_level (rc, "majority"); |
| 330 | + mongoc_database_set_read_concern (database, rc); |
| 331 | + |
| 332 | + read_prefs = mongoc_read_prefs_new (MONGOC_READ_SECONDARY); |
| 333 | + mongoc_database_set_read_prefs (database, read_prefs); |
| 334 | + |
| 335 | + collection = mongoc_database_get_collection (database, "test"); |
| 336 | + |
| 337 | + ASSERT_CMPINT32 (collection->write_concern->w, ==, 2); |
| 338 | + ASSERT_CMPSTR (collection->read_concern->level, "majority"); |
| 339 | + ASSERT_CMPINT (collection->read_prefs->mode, ==, MONGOC_READ_SECONDARY); |
| 340 | + |
| 341 | + mongoc_collection_destroy (collection); |
| 342 | + mongoc_read_prefs_destroy (read_prefs); |
| 343 | + mongoc_read_concern_destroy (rc); |
| 344 | + mongoc_write_concern_destroy (wc); |
| 345 | + mongoc_database_destroy (database); |
| 346 | + mongoc_client_destroy (client); |
| 347 | +} |
| 348 | + |
306 | 349 | static void
|
307 | 350 | test_get_collection_names (void)
|
308 | 351 | {
|
@@ -481,6 +524,8 @@ test_database_install (TestSuite *suite)
|
481 | 524 | TestSuite_Add (suite, "/Database/create_collection", test_create_collection);
|
482 | 525 | TestSuite_Add (suite, "/Database/get_collection_info",
|
483 | 526 | test_get_collection_info);
|
| 527 | + TestSuite_Add (suite, "/Database/get_collection", |
| 528 | + test_get_collection); |
484 | 529 | TestSuite_Add (suite, "/Database/get_collection_names",
|
485 | 530 | test_get_collection_names);
|
486 | 531 | TestSuite_Add (suite, "/Database/get_collection_names_error",
|
|
0 commit comments