23 require_once(
"./test_common.php");
38 public $fossology_testconfig;
41 public $scheduler_path;
52 global $fossology_testconfig;
53 global $scheduler_path;
57 $fossology_testconfig = getenv(
'FOSSOLOGY_TESTCONFIG');
59 if (empty($fossology_testconfig)) $fossology_testconfig =
"/usr/local/etc/fossology/";
60 fwrite(STDOUT, __METHOD__ .
" got fossology_testconfig = '$fossology_testconfig'\n");
62 $cp2foss_path =
"cp2foss";
65 $scheduler_path = $fossology_testconfig .
"/mods-enabled/scheduler/agent/fo_scheduler";
66 if (!is_executable($scheduler_path)) {
67 print
"Error: Scheduler path '$scheduler_path' is not executable!\n";
72 $scheduler_cmd =
"$scheduler_path --daemon --reset --verbose=952 -c $fossology_testconfig";
73 print
"DEBUG: Starting scheduler with '$scheduler_cmd'\n";
74 exec($scheduler_cmd, $output, $return_var);
76 if ( $return_var != 0 ) {
77 print
"Error: Could not start scheduler '$scheduler_path'\n";
82 $PG_CONN = connect_to_DB($fossology_testconfig);
85 print
"\nStarting functional test for cp2foss. \n";
99 global $fossology_testconfig;
100 global $cp2foss_path;
103 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
105 $test_dbh = $PG_CONN;
107 $auth =
"--username fossy --password fossy -c $fossology_testconfig -s ";
111 $command =
"$cp2foss_path $auth ./test_cp2foss.php";
112 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
113 $last = exec(
"$command 2>&1", $out, $rtn);
114 $repo_string =
"Uploading to folder: 'Software Repository'";
115 $repo_pos = strpos($out[1], $repo_string);
116 $output_msg_count = count($out);
117 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos);\n";
118 $this->assertGreaterThan(0, $repo_pos);
119 print
"DEBUG: \$this->assertEquals(4, $output_msg_count);\n";
120 $this->assertEquals(4, $output_msg_count);
123 if ($out && $out[3]) {
124 $upload_id = get_upload_id($out[3]);
125 print
"DEBUG: Upload_id is $upload_id\n";
128 print
"DEBUG: Did not get an upload_id!\n";
129 $this->assertFalse(TRUE);
132 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
133 $this->assertEquals(1, $agent_status);
138 $command =
"$cp2foss_path $auth ./";
139 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
140 $last = exec(
"$command 2>&1", $out, $rtn);
141 $repo_string =
"Uploading to folder: 'Software Repository'";
142 $repo_pos = strpos($out[1], $repo_string);
143 $output_msg_count = count($out);
144 $this->assertGreaterThan(0, $repo_pos);
145 $this->assertEquals(4, $output_msg_count);
148 if ($out && $out[3]) {
149 $upload_id = get_upload_id($out[3]);
150 }
else $this->assertFalse(TRUE);
152 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
153 $this->assertEquals(1, $agent_status);
158 $upload_path =
"upload_path";
159 $command =
"$cp2foss_path $auth ./ -f $upload_path -d upload_des -q all -v";
160 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
161 $last = exec(
"$command 2>&1", $out, $rtn);
162 $repo_string =
"Uploading to folder: '/$upload_path'";
163 $repo_pos = strpos($out[7], $repo_string);
164 $output_msg_count = count($out);
165 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos)\n";
166 $this->assertGreaterThan(0, $repo_pos);
167 $scheduled_agent_info_1 =
"agent_pkgagent is queued to run on";
168 $scheduled_agent_info_2 =
"agent_nomos is queued to run on";
169 $scheduled_agent_info_3 =
"agent_monk is queued to run on";
170 $scheduled_agent_info_4 =
"agent_mimetype is queued to run on";
171 $scheduled_agent_info_5 =
"agent_copyright is queued to run on";
173 $pos = strpos($out[$output_msg_count - 1], $scheduled_agent_info_1);
174 $this->assertEquals(0, $pos);
176 $pos = strpos($out[$output_msg_count - 2], $scheduled_agent_info_2);
177 $this->assertEquals(0, $pos);
179 $pos = strpos($out[$output_msg_count - 3], $scheduled_agent_info_3);
180 $this->assertEquals(0, $pos);
182 $pos = strpos($out[$output_msg_count - 4], $scheduled_agent_info_4);
183 $this->assertEquals(0, $pos);
185 $pos = strpos($out[$output_msg_count - 5], $scheduled_agent_info_5);
186 $this->assertEquals(0, $pos);
190 if ($out && $out[11]) {
191 $upload_id = get_upload_id($out[11]);
192 }
else $this->assertFalse(TRUE);
194 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
195 $this->assertEquals(1, $agent_status);
197 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
198 $this->assertEquals(1, $agent_status);
200 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
201 $this->assertEquals(1, $agent_status);
203 $agent_status = check_agent_status($test_dbh,
"mimetype", $upload_id);
204 $this->assertEquals(1, $agent_status);
206 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
207 $this->assertEquals(1, $agent_status);
213 $command =
"$cp2foss_path $auth -q all -A -f test/exclude -n 'test exclue dir' -d 'test des exclude dir' -X .svn ./ -v";
214 fwrite(STDOUT,
"DEBUG: Running $command\n");
215 $last = exec(
"$command 2>&1", $out, $rtn);
218 if ($out && $out[23]) {
219 $upload_id = get_upload_id($out[23]);
220 }
else $this->assertFalse(TRUE);
222 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
223 $this->assertEquals(1, $agent_status);
227 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
232 public static function tearDownAfterClass() {
234 global $fossology_testconfig;
235 global $scheduler_path;
238 print
"Stopping the scheduler\n";
239 $scheduler_cmd =
"$scheduler_path -k -c $fossology_testconfig";
240 exec($scheduler_cmd, $output, $return_var);
241 if ( $return_var != 0 ) {
242 print
"Error: Could not stop scheduler via '$scheduler_cmd'\n";
249 print
"End of functional tests for cp2foss \n";
static setUpBeforeClass()
add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
test_upload_from_server()
upload from server