summaryrefslogtreecommitdiff
path: root/tests/unit/mongo/client/connect.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/mongo/client/connect.c')
-rw-r--r--tests/unit/mongo/client/connect.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/unit/mongo/client/connect.c b/tests/unit/mongo/client/connect.c
new file mode 100644
index 0000000..fc390ea
--- /dev/null
+++ b/tests/unit/mongo/client/connect.c
@@ -0,0 +1,34 @@
+#include "test.h"
+#include "tap.h"
+#include "mongo-client.h"
+
+#include <errno.h>
+
+void
+test_mongo_connect (void)
+{
+ mongo_connection *c;
+
+ ok (mongo_connect (NULL, 27010) == NULL,
+ "mongo_connect() fails with a NULL host");
+ ok (errno == EINVAL,
+ "mongo_connect() should fail with EINVAL if host is NULL");
+
+ begin_network_tests (4);
+
+ ok (mongo_connect ("invalid.example.com", 27017) == NULL,
+ "Connecting to an invalid host fails");
+ ok (mongo_connect ("example.com", 27017) == NULL,
+ "Connecting to an unavailable host/port fails");
+ ok (mongo_connect ("/does/not/exist.sock", MONGO_CONN_LOCAL) == NULL,
+ "Connecting to an unavailable unix socket fails");
+
+ ok ((c = mongo_connect (config.primary_host,
+ config.primary_port)) != NULL,
+ "Connecting to the primary server works");
+ mongo_disconnect (c);
+
+ end_network_tests ();
+}
+
+RUN_TEST (6, mongo_connect);