summaryrefslogtreecommitdiff
path: root/tests/func/mongo/sync/f_sync_write_error.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-12-02 10:06:21 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-12-02 10:06:21 +0100
commitfd841e416881cc0392e61ec312c1870f3a0004bd (patch)
tree8357ba56e79d614ba57f722e7878b853591dc339 /tests/func/mongo/sync/f_sync_write_error.c
Initial import of libmongo-client version 0.1.8-2
Diffstat (limited to 'tests/func/mongo/sync/f_sync_write_error.c')
-rw-r--r--tests/func/mongo/sync/f_sync_write_error.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/func/mongo/sync/f_sync_write_error.c b/tests/func/mongo/sync/f_sync_write_error.c
new file mode 100644
index 0000000..b6d4750
--- /dev/null
+++ b/tests/func/mongo/sync/f_sync_write_error.c
@@ -0,0 +1,52 @@
+#include "test.h"
+#include <mongo.h>
+
+#include <errno.h>
+#include <sys/socket.h>
+
+#include "libmongo-private.h"
+
+#define INVALID_NS "test.$Uncle$.Dagobert$"
+
+void
+test_func_mongo_sync_write_error (void)
+{
+ mongo_sync_connection *conn;
+ bson *b;
+ const gchar *error_msg;
+
+ b = bson_new ();
+ bson_append_int32 (b, "f_sync_write_error", 1);
+ bson_finish (b);
+
+ conn = mongo_sync_connect (config.primary_host, config.primary_port,
+ TRUE);
+
+ ok (mongo_sync_cmd_insert (conn, config.ns, b, NULL) == TRUE,
+ "Inserting works with correct namespace when safe mode is off");
+
+ ok (mongo_sync_cmd_insert (conn, INVALID_NS, b, NULL) == TRUE,
+ "Inserting works with invalid namespace when safe mode is off");
+
+ error_msg = mongo_sync_conn_get_last_error (conn);
+ ok (error_msg == NULL,
+ "When safe mode is off, there is no error msg, even if ns is invalid.");
+
+ ok (mongo_sync_conn_set_safe_mode (conn, TRUE) == TRUE,
+ "Setting safe mode works.");
+
+ ok (mongo_sync_cmd_insert (conn, config.ns, b, NULL) == TRUE,
+ "Inserting works with correct namespace when safe mode is on");
+
+ ok (mongo_sync_cmd_insert (conn, INVALID_NS, b, NULL) == FALSE,
+ "Inserting fails with invalid namespace when safe mode is on");
+
+ error_msg = mongo_sync_conn_get_last_error (conn);
+
+ ok (error_msg != NULL,
+ "Inserting failed in safe mode, so we should have an error msg");
+
+ mongo_sync_disconnect (conn);
+}
+
+RUN_NET_TEST (7, func_mongo_sync_write_error);