summaryrefslogtreecommitdiff
path: root/tests/unit/mongo/sync-gridfs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/mongo/sync-gridfs')
-rw-r--r--tests/unit/mongo/sync-gridfs/sync_gridfs_file_get_metadata.c23
-rw-r--r--tests/unit/mongo/sync-gridfs/sync_gridfs_free.c35
-rw-r--r--tests/unit/mongo/sync-gridfs/sync_gridfs_get_set_chunk_size.c33
-rw-r--r--tests/unit/mongo/sync-gridfs/sync_gridfs_list.c34
-rw-r--r--tests/unit/mongo/sync-gridfs/sync_gridfs_new.c54
-rw-r--r--tests/unit/mongo/sync-gridfs/sync_gridfs_remove.c34
6 files changed, 213 insertions, 0 deletions
diff --git a/tests/unit/mongo/sync-gridfs/sync_gridfs_file_get_metadata.c b/tests/unit/mongo/sync-gridfs/sync_gridfs_file_get_metadata.c
new file mode 100644
index 0000000..2be34e5
--- /dev/null
+++ b/tests/unit/mongo/sync-gridfs/sync_gridfs_file_get_metadata.c
@@ -0,0 +1,23 @@
+#include "test.h"
+#include "mongo.h"
+
+void
+test_mongo_sync_gridfs_file_get_metadata (void)
+{
+ ok (mongo_sync_gridfs_file_get_id (NULL) == NULL,
+ "mongo_sync_gridfs_file_get_id() fails with a NULL file");
+ ok (mongo_sync_gridfs_file_get_length (NULL) == -1,
+ "mongo_sync_gridfs_file_get_length() fails with a NULL file");
+ ok (mongo_sync_gridfs_file_get_chunk_size (NULL) == -1,
+ "mongo_sync_gridfs_file_get_chunk_size() fails with a NULL file");
+ ok (mongo_sync_gridfs_file_get_md5 (NULL) == NULL,
+ "mongo_sync_gridfs_file_get_md5() fails with a NULL file");
+ ok (mongo_sync_gridfs_file_get_date (NULL) == -1,
+ "mongo_sync_gridfs_file_get_date() fails with a NULL file");
+ ok (mongo_sync_gridfs_file_get_metadata (NULL) == NULL,
+ "mongo_sync_gridfs_file_get_metadata() fails with a NULL file");
+ ok (mongo_sync_gridfs_file_get_chunks (NULL) == -1,
+ "mongo_sync_gridfs_file_get_chunks() fails with a NULL file");
+}
+
+RUN_TEST (7, mongo_sync_gridfs_file_get_metadata);
diff --git a/tests/unit/mongo/sync-gridfs/sync_gridfs_free.c b/tests/unit/mongo/sync-gridfs/sync_gridfs_free.c
new file mode 100644
index 0000000..1c8c2d6
--- /dev/null
+++ b/tests/unit/mongo/sync-gridfs/sync_gridfs_free.c
@@ -0,0 +1,35 @@
+#include "test.h"
+#include "mongo.h"
+
+#include <errno.h>
+
+void
+test_mongo_sync_gridfs_free (void)
+{
+ mongo_sync_connection *conn;
+ mongo_sync_gridfs *gfs;
+
+ errno = 0;
+ mongo_sync_gridfs_free (NULL, FALSE);
+ cmp_ok (errno, "==", ENOTCONN,
+ "mongo_sync_gridfs_free() with a NULL connection shall set errno");
+
+ begin_network_tests (2);
+
+ conn = mongo_sync_connect (config.primary_host, config.primary_port, FALSE);
+ gfs = mongo_sync_gridfs_new (conn, config.gfs_prefix);
+
+ mongo_sync_gridfs_free (gfs, FALSE);
+ cmp_ok (errno, "==", 0,
+ "mongo_sync_gridfs_free() should clear errno on success");
+
+ gfs = mongo_sync_gridfs_new (conn, config.gfs_prefix);
+ mongo_sync_gridfs_free (gfs, TRUE);
+ cmp_ok (errno, "==", 0,
+ "mongo_sync_gridfs_free() works when asked to free the "
+ "connection too");
+
+ end_network_tests ();
+}
+
+RUN_TEST (3, mongo_sync_gridfs_free);
diff --git a/tests/unit/mongo/sync-gridfs/sync_gridfs_get_set_chunk_size.c b/tests/unit/mongo/sync-gridfs/sync_gridfs_get_set_chunk_size.c
new file mode 100644
index 0000000..5d17986
--- /dev/null
+++ b/tests/unit/mongo/sync-gridfs/sync_gridfs_get_set_chunk_size.c
@@ -0,0 +1,33 @@
+#include "test.h"
+#include "mongo.h"
+
+void
+test_mongo_sync_gridfs_get_set_chunk_size (void)
+{
+ mongo_sync_gridfs *gfs;
+
+ ok (mongo_sync_gridfs_get_chunk_size (NULL) == -1,
+ "mongo_sync_gridfs_get_chunk_size() fails with a NULL gfs");
+ ok (mongo_sync_gridfs_set_chunk_size (NULL, 16 * 1024) == FALSE,
+ "mongo_sync_gridfs_set_chunk_size() fails with a NULL gfs");
+
+ begin_network_tests (3);
+
+ gfs = mongo_sync_gridfs_new (mongo_sync_connect (config.primary_host,
+ config.primary_port,
+ FALSE),
+ config.gfs_prefix);
+
+ ok (mongo_sync_gridfs_set_chunk_size (gfs, -1) == FALSE,
+ "mongo_sync_gridfs_set_chunk_size() fails if the size is invalid");
+ ok (mongo_sync_gridfs_set_chunk_size (gfs, 12345),
+ "mongo_sync_gridfs_set_chunk_size() works");
+ cmp_ok (mongo_sync_gridfs_get_chunk_size (gfs), "==", 12345,
+ "mongo_sync_gridfs_get_chunk_size() works");
+
+ mongo_sync_gridfs_free (gfs, TRUE);
+
+ end_network_tests ();
+}
+
+RUN_TEST (5, mongo_sync_gridfs_get_set_chunk_size);
diff --git a/tests/unit/mongo/sync-gridfs/sync_gridfs_list.c b/tests/unit/mongo/sync-gridfs/sync_gridfs_list.c
new file mode 100644
index 0000000..e5857ea
--- /dev/null
+++ b/tests/unit/mongo/sync-gridfs/sync_gridfs_list.c
@@ -0,0 +1,34 @@
+#include "test.h"
+#include "mongo.h"
+
+void
+test_mongo_sync_gridfs_list (void)
+{
+ mongo_sync_gridfs *gfs;
+ bson *query;
+
+ query = bson_build (BSON_TYPE_STRING, "bogus-key", "bogus-value", -1,
+ BSON_TYPE_NONE);
+ bson_finish (query);
+
+ ok (mongo_sync_gridfs_list (NULL, NULL) == NULL,
+ "mongo_sync_gridfs_list() fails with a NULL GridFS");
+
+ begin_network_tests (1);
+
+ gfs = mongo_sync_gridfs_new
+ (mongo_sync_connect (config.primary_host, config.primary_port, FALSE),
+ config.gfs_prefix);
+
+ ok (mongo_sync_gridfs_list (gfs, query) == NULL,
+ "mongo_sync_gridfs_list() fails with a query that does not match "
+ "anything");
+
+ mongo_sync_gridfs_free (gfs, TRUE);
+
+ end_network_tests ();
+
+ bson_free (query);
+}
+
+RUN_TEST (2, mongo_sync_gridfs_list);
diff --git a/tests/unit/mongo/sync-gridfs/sync_gridfs_new.c b/tests/unit/mongo/sync-gridfs/sync_gridfs_new.c
new file mode 100644
index 0000000..20d6fea
--- /dev/null
+++ b/tests/unit/mongo/sync-gridfs/sync_gridfs_new.c
@@ -0,0 +1,54 @@
+#include "test.h"
+#include "mongo.h"
+
+#include <errno.h>
+
+void
+test_mongo_sync_gridfs_new (void)
+{
+ mongo_sync_connection *conn;
+ mongo_sync_gridfs *gfs;
+ gchar *f, *c;
+
+ conn = test_make_fake_sync_conn (4, TRUE);
+
+ ok (mongo_sync_gridfs_new (NULL, "test.fs") == NULL,
+ "mongo_sync_gridfs_new() should fail with a NULL connection");
+
+ ok (mongo_sync_gridfs_new (conn, "test.fs") == NULL,
+ "mongo_sync_gridfs_new() should fail with a bogus connection");
+
+ ok (mongo_sync_gridfs_new (conn, NULL) == NULL,
+ "mongo_sync_gridfs_new() should fail with a NULL ns prefix");
+
+ ok (mongo_sync_gridfs_new (conn, "bogus") == NULL,
+ "mongo_sync_gridfs_new() should fail with a bogus ns prefix");
+
+ mongo_sync_disconnect (conn);
+
+ begin_network_tests (4);
+
+ f = g_strconcat (config.gfs_prefix, ".files", NULL);
+ c = g_strconcat (config.gfs_prefix, ".chunks", NULL);
+
+ conn = mongo_sync_connect (config.primary_host, config.primary_port, FALSE);
+
+ gfs = mongo_sync_gridfs_new (conn, config.gfs_prefix);
+ ok (gfs != NULL,
+ "mongo_sync_gridfs_new() works");
+ is (gfs->ns.prefix, config.gfs_prefix,
+ "The namespace prefix is as specified");
+ is (gfs->ns.files, f,
+ "The files namespace is correct");
+ is (gfs->ns.chunks, c,
+ "The chunks namespace is correct");
+ mongo_sync_gridfs_free (gfs, FALSE);
+
+ mongo_sync_disconnect (conn);
+
+ g_free (f);
+ g_free (c);
+ end_network_tests ();
+}
+
+RUN_TEST (8, mongo_sync_gridfs_new);
diff --git a/tests/unit/mongo/sync-gridfs/sync_gridfs_remove.c b/tests/unit/mongo/sync-gridfs/sync_gridfs_remove.c
new file mode 100644
index 0000000..88eb40b
--- /dev/null
+++ b/tests/unit/mongo/sync-gridfs/sync_gridfs_remove.c
@@ -0,0 +1,34 @@
+#include "test.h"
+#include "mongo.h"
+
+void
+test_mongo_sync_gridfs_remove (void)
+{
+ mongo_sync_gridfs *gfs;
+ bson *query;
+
+ query = bson_build (BSON_TYPE_STRING, "bogus-key", "bogus-value", -1,
+ BSON_TYPE_NONE);
+ bson_finish (query);
+
+ ok (mongo_sync_gridfs_remove (NULL, NULL) == FALSE,
+ "mongo_sync_gridfs_remove() fails with a NULL GridFS");
+
+ begin_network_tests (1);
+
+ gfs = mongo_sync_gridfs_new
+ (mongo_sync_connect (config.primary_host, config.primary_port, FALSE),
+ config.gfs_prefix);
+
+ ok (mongo_sync_gridfs_remove (gfs, query) == FALSE,
+ "mongo_sync_gridfs_remove() fails with a query that does not match "
+ "anything");
+
+ mongo_sync_gridfs_free (gfs, TRUE);
+
+ end_network_tests ();
+
+ bson_free (query);
+}
+
+RUN_TEST (2, mongo_sync_gridfs_remove);