File: sync_cmd_is_master.c

package info (click to toggle)
libmongo-client 0.1.5-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,256 kB
  • sloc: ansic: 13,795; makefile: 297; perl: 137; sh: 41
file content (65 lines) | stat: -rw-r--r-- 1,460 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "test.h"
#include "mongo.h"

#include <errno.h>

void
test_mongo_sync_cmd_is_master_net_secondary (void)
{
  mongo_sync_connection *conn;

  skip (!config.secondary_host, 1,
	"Secondary server not configured");

  errno = 0;
  conn = mongo_sync_connect (config.secondary_host, config.secondary_port,
			     TRUE);
  ok (mongo_sync_cmd_is_master (conn) == FALSE && errno == 0,
      "mongo_sync_cmd_is_master() works correctly on a secondary");
  mongo_sync_disconnect (conn);

  endskip;
}

void
test_mongo_sync_cmd_is_master_net (void)
{
  mongo_sync_connection *conn;

  begin_network_tests (2);

  conn = mongo_sync_connect (config.primary_host, config.primary_port, TRUE);
  ok (mongo_sync_cmd_is_master (conn) == TRUE,
      "mongo_sync_cmd_is_master() works");
  mongo_sync_disconnect (conn);

  test_mongo_sync_cmd_is_master_net_secondary ();

  end_network_tests ();
}

void
test_mongo_sync_cmd_is_master (void)
{
  mongo_sync_connection *c;

  c = test_make_fake_sync_conn (-1, FALSE);

  errno = 0;
  ok (mongo_sync_cmd_is_master (NULL) == FALSE,
      "mongo_sync_cmd_is_master fails with a NULL connection");
  cmp_ok (errno, "==", ENOTCONN,
	  "errno is set to ENOTCONN");

  errno = 0;
  ok (mongo_sync_cmd_is_master (c) == FALSE,
      "mongo_sync_cmd_is_master() works");
  cmp_ok (errno, "!=", 0,
	  "errno is not 0");

  mongo_sync_disconnect (c);

  test_mongo_sync_cmd_is_master_net ();
}

RUN_TEST (6, mongo_sync_cmd_is_master);