rvm  1.11
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test-rconfig-043.cc
Go to the documentation of this file.
1 #include "config.h"
2 
3 #include <iostream>
4 #include <string>
5 #include <cassert>
6 
7 #ifdef HAVE_UNISTD_H
8 #include <unistd.h>
9 #endif
10 
11 #include <errno.h>
12 
13 #include "asserts.h"
14 #include "types.h"
15 #include "error.h"
16 #include "estring.h"
17 #include "fs.h"
18 #include "tstamp.h"
19 #include "rconfig.h"
20 #include "test-rconfig-setup.h"
21 
22 #define ERR_OUT(e) std::cerr << e;
23 // #define ERR_OUT(e)
24 
25 void test(void)
26 {
27  char const * argv[256] = { 0 };
28  int argc = 0;
29  bool thrown = false;
30  std::vector<std::string> opt_vec;
31 
32  argv[argc++] = "<program>";
33  argv[argc++] = "--archive";
34 
35  config.default_file("./test-rconfig.dir/job.dir/file-7.conf");
36  config.default_logdir("./test-rconfig.dir/log.dir");
37  try {
38  config.init(argc, argv);
39  }
40  catch(error e) {
41  ERR_OUT(e);
42  thrown = true;
43  }
44  catch(...) {
45  assert(0);
46  }
47  assert(!thrown);
48  assert(config.default_job().groupname == "group-A");
49  assert(config.default_job().hostname == "host-A");
52  assert(config.default_job().rsync_behavior.map_value().size() == 1);
55  assert(config.default_job().rsync_hardlink == false);
56  assert(config.default_job().rsync_options == "--some -options for-rsync");
57  assert(config.default_job().rsync_remote_user == "alice");
58  assert(config.default_job().rsync_remote_port == 4338);
59  assert(config.jobs().size() == 5);
60  assert(config.jobs()[0].jobname == "job-A");
61  assert(config.jobs()[0].groupname == "group-A");
62  assert(config.jobs()[0].hostname == "host-A");
63  assert(config.jobs()[0].rsync_behavior.default_value()
65  assert(config.jobs()[0].rsync_behavior.map_value().size() == 9);
66  assert(config.jobs()[0].rsync_behavior[0] == rsync_behavior::ok);
67  assert(config.jobs()[0].rsync_behavior[1] == rsync_behavior::fail);
68  assert(config.jobs()[0].rsync_behavior[2] == rsync_behavior::fail);
69  assert(config.jobs()[0].rsync_behavior[4] == rsync_behavior::fail);
70  assert(config.jobs()[0].rsync_behavior[23]
72  assert(config.jobs()[0].rsync_behavior[124] == rsync_behavior::fail);
73  assert(config.jobs()[0].rsync_behavior[125] == rsync_behavior::fail);
74  assert(config.jobs()[0].rsync_behavior[126] == rsync_behavior::fail);
75  assert(config.jobs()[0].rsync_behavior[127] == rsync_behavior::fail);
76  assert(config.jobs()[0].rsync_connection == job::connection_local);
77  assert(config.jobs()[0].rsync_hardlink == true);
78  assert(config.jobs()[0].rsync_multi_hardlink == false);
79  assert(config.jobs()[0].rsync_multi_hardlink_max == 20);
80  assert(config.jobs()[0].rsync_options == "--some -options for-rsync some more \"options for\" the\\trsync\\ program");
81  opt_vec.clear();
82  opt_vec = config.jobs()[0].generate_rsync_options_vector();
83  assert(opt_vec[0] == "--some");
84  assert(opt_vec[1] == "-options");
85  assert(opt_vec[2] == "for-rsync");
86  assert(opt_vec[3] == "some");
87  assert(opt_vec[4] == "more");
88  assert(opt_vec[5] == "options for");
89  assert(opt_vec[6] == "the\trsync program");
90  assert(opt_vec.size() == 7);
91  assert(config.jobs()[0].rsync_remote_user == "");
92  assert(config.jobs()[0].rsync_remote_port == 0);
93  assert(config.jobs()[1].jobname.size() == 0);
94  assert(config.jobs()[1].groupname == "group-A");
95  assert(config.jobs()[1].hostname == "host-B");
96  assert(config.jobs()[1].rsync_behavior.default_value()
98  assert(config.jobs()[1].rsync_behavior.map_value().size() == 1);
99  assert(config.jobs()[1].rsync_behavior.map_value().find(5)->second
100  == rsync_behavior::ok);
101  assert(config.jobs()[1].rsync_connection == job::connection_server);
102  assert(config.jobs()[1].rsync_hardlink == false);
103  assert(config.jobs()[1].rsync_remote_user == "alice");
104  assert(config.jobs()[1].rsync_remote_port == 4338);
105  assert(config.jobs()[2].hostname == "host-C");
106  assert(config.jobs()[2].rsync_hardlink == true);
107  assert(config.jobs()[2].rsync_multi_hardlink == true);
108  assert(config.jobs()[2].rsync_multi_hardlink_max == 7);
109  assert(config.jobs()[3].jobname == "job-D");
110  assert(config.jobs()[3].rsync_options == "--some -options for-rsync -e \"-i foo\"");
111  opt_vec.clear();
112  opt_vec = config.jobs()[3].generate_rsync_options_vector();
113  assert(opt_vec[0] == "--some");
114  assert(opt_vec[1] == "-options");
115  assert(opt_vec[2] == "for-rsync");
116  assert(opt_vec[3] == "-e");
117  assert(opt_vec[4] == "-i foo");
118  assert(config.jobs()[4].jobname == "job-E");
119  assert(config.jobs()[4].rsync_options == "--some -options for-rsync --rsh=\"/usr/bin/rsh -i foo\"");
120  opt_vec.clear();
121  opt_vec = config.jobs()[4].generate_rsync_options_vector();
122  assert(opt_vec[0] == "--some");
123  assert(opt_vec[1] == "-options");
124  assert(opt_vec[2] == "for-rsync");
125  assert(opt_vec[3] == "--rsh=/usr/bin/rsh -i foo");
126 }
127 
128 int main(int argc, char const * argv[])
129 {
130  cleanup();
131  setup();
132  try {
133  test();
134  }
135  catch(error e) {
136  std::cerr << e;
137  assert(0);
138  }
139  catch(...) {
140  std::cerr << err_unknown;
141  assert(0);
142  }
143  cleanup();
144  return(0);
145 }
146 
void init(int argc, char const *argv[])
Initialize the configuration manager from rvm's command line options.
Definition: rconfig.cc:1218
rsync_connection_type rsync_connection
Definition: rconfig.h:175
Basic types definitions and templates.
void setup(void)
Definition: test-logger.cc:62
const value_type default_value(void) const
Return the default action.
Definition: rconfig.cc:543
void default_file(const std::string &a_path)
Set the default configuration filename.
Definition: rconfig.cc:1484
void cleanup(void)
Definition: test-fs.cc:63
class rsync_behavior rsync_behavior
Definition: rconfig.h:174
uint16 rsync_remote_port
Definition: rconfig.h:184
const map_type & map_value(void) const
Return an std::map of exit codes to actions.
Definition: rconfig.cc:549
void default_logdir(const std::string &a_path)
Return the default log-dir.
Definition: rconfig.cc:1499
#define err_unknown
Definition: error.h:114
void test(void)
std::string rsync_remote_user
Definition: rconfig.h:181
std::string groupname
Definition: rconfig.h:170
An error class.
Definition: error.h:72
bool rsync_hardlink
Definition: rconfig.h:176
std::string hostname
Definition: rconfig.h:171
#define ERR_OUT(e)
configuration_manager config
The global configuration manager instance.
Definition: rconfig.cc:3364
int main(int argc, char const *argv[])
const job & default_job(void) const
Return the default job configuration.
Definition: rconfig.cc:1658
const jobs_type & jobs(void) const
Return a list of jobs.
Definition: rconfig.cc:1667
std::string rsync_options
Definition: rconfig.h:179