2 // Created by jlr on 4/9/18.
11 #include <mon_internal.h>
13 #define JSON_DUMP_OPTS 0
15 static char *show_plain()
17 MON_REQ *req = mon_req_new(NULL, MON_CMD_SHOW);
18 json_t *req_json = mon_req_encode(req);
19 char *result = json_dumps(req_json, JSON_DUMP_OPTS);
23 json_decref(req_json);
28 static char *show_options(const MON_OPT_TYPE *opts)
30 MON_REQ *req = mon_req_new(NULL, MON_CMD_SHOW);
31 json_t *req_json = NULL;
36 while (*opts != OPT_TYPE_UNKNOWN) {
37 assert(MON_SUCCESS == mon_req_add_option(req, *opts));
41 req_json = mon_req_encode(req);
44 result = json_dumps(req_json, JSON_DUMP_OPTS);
47 json_decref(req_json);
52 static char *read_file(const char *filename)
54 FILE *f = fopen(filename, "r");
57 ssize_t n = getline(&s, &nn, f);
60 if( (n > 0) && (s[n-1] == '\n'))
68 MON_OPT_TYPE opts[10];
69 char *expected = NULL;
71 // Test show without options
73 expected = read_file("req_show_no_options.test");
75 assert(strcmp(expected, s) == 0);
79 // Test show with empty options (this mostly tests the test)
80 opts[0] = OPT_TYPE_UNKNOWN;
81 s = show_options(opts);
82 expected = read_file("req_show_no_options.test");
84 assert(strcmp(expected, s) == 0);
88 // Test show with many options
89 opts[0] = OPT_TYPE_SHOW_CONFIG_FILES;
90 opts[1] = OPT_TYPE_SHOW_VERSION;
91 opts[2] = OPT_TYPE_SHOW_UPTIME;
92 opts[3] = OPT_TYPE_SHOW_TID_REQS_PROCESSED;
93 opts[4] = OPT_TYPE_SHOW_TID_REQS_PENDING;
94 opts[5] = OPT_TYPE_SHOW_ROUTES;
95 opts[6] = OPT_TYPE_SHOW_COMMUNITIES;
96 opts[7] = OPT_TYPE_UNKNOWN;
97 s = show_options(opts);
98 expected = read_file("req_show_all_options.test");
100 assert(strcmp(expected, s) == 0);