19 require_once(
"./test_common.php");
31 public $SYSCONF_DIR =
"/usr/local/etc/fossology/";
40 public $fossology_testconfig;
43 public $scheduler_path;
55 global $fossology_testconfig;
56 global $scheduler_path;
59 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
66 $fossology_testconfig = getenv(
'FOSSOLOGY_TESTCONFIG');
67 fwrite(STDOUT, __METHOD__ .
" got fossology_testconfig = '$fossology_testconfig'\n");
71 $fo_base_dir = realpath(__DIR__ .
'/../..');
72 $cp2foss_path = $fo_base_dir .
"/cli/cp2foss";
73 if (!is_executable($cp2foss_path)) {
74 print
"Error: cp2foss path '" . $cp2foss_path .
"' is not executable!\n";
77 $cp2foss_path .=
" -s ";
80 $scheduler_path = $fossology_testconfig .
"/mods-enabled/scheduler/agent/fo_scheduler";
81 if (!is_executable($scheduler_path)) {
82 print
"Error: Scheduler path '$scheduler_path' is not executable!\n";
87 $scheduler_cmd =
"$scheduler_path --daemon --reset --verbose=952 -c $fossology_testconfig";
88 fwrite(STDOUT,
"DEBUG: Starting scheduler with '$scheduler_cmd'\n");
89 exec($scheduler_cmd, $output, $return_var);
91 if ( $return_var != 0 ) {
92 print
"Error: Could not start scheduler '$scheduler_path'\n";
96 print
"\nStarting functional test for cp2foss. \n";
102 protected function setUp()
105 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
132 global $fossology_testconfig;
133 global $cp2foss_path;
135 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
137 $test_dbh = connect_to_DB($fossology_testconfig);
139 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
144 $command =
"$cp2foss_path $auth -q all -d 'regular expression testing' '../*.php' -v";
145 fwrite(STDOUT,
"DEBUG: Running $command\n");
146 $last = exec(
"$command 2>&1", $out, $rtn);
151 if ($out && $out[13]) {
152 $upload_id = get_upload_id($out[6]);
154 $this->assertFalse(
true);
156 fwrite(STDOUT,
"DEBUG: $upload_id \n");
158 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
159 $this->assertEquals(1, $agent_status);
161 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
162 $this->assertEquals(1, $agent_status);
164 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
165 $this->assertEquals(1, $agent_status);
167 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
168 $this->assertEquals(1, $agent_status);
171 $is_exist = check_file_uploadtree($test_dbh,
'src', $upload_id);
172 fwrite(STDOUT,
"DEBUG: is_exist is:$is_exist\n");
173 $this->assertEquals(0, $is_exist);
178 $command =
"$cp2foss_path $auth ./test_cp2foss.php";
179 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
180 $last = exec(
"$command 2>&1", $out, $rtn);
181 #print "DEBUG: output is:\n"; 184 $repo_string =
"Uploading to folder: 'Software Repository'";
185 $repo_pos = strpos($out[2], $repo_string);
186 $output_msg_count = count($out);
187 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos);\n";
188 $this->assertGreaterThan(0, $repo_pos);
189 print
"DEBUG: \$this->assertEquals(4, $output_msg_count);\n";
190 $this->assertEquals(5, $output_msg_count);
193 if ($out && $out[4]) {
194 $upload_id = get_upload_id($out[4]);
195 print
"DEBUG: Upload_id is $upload_id\n";
197 print
"DEBUG: Did not get an upload_id!\n";
198 $this->assertFalse(
true);
201 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
202 $this->assertEquals(1, $agent_status);
207 $command =
"$cp2foss_path $auth ./";
208 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
209 $last = exec(
"$command 2>&1", $out, $rtn);
211 $repo_string =
"Uploading to folder: 'Software Repository'";
212 $repo_pos = strpos($out[2], $repo_string);
213 $output_msg_count = count($out);
214 $this->assertGreaterThan(0, $repo_pos);
215 $this->assertEquals(5, $output_msg_count);
218 if ($out && $out[4]) {
219 $upload_id = get_upload_id($out[4]);
221 $this->assertFalse(
true);
224 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
225 $this->assertEquals(1, $agent_status);
230 $upload_path =
"upload_path";
231 $command =
"$cp2foss_path $auth ./ -f $upload_path -d upload_des -q all -v";
232 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
233 $last = exec(
"$command 2>&1", $out, $rtn);
235 $repo_string =
"Uploading to folder: '/$upload_path'";
236 $repo_pos = strpos($out[8], $repo_string);
237 $output_msg_count = count($out);
238 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos), $repo_string\n";
239 $this->assertGreaterThan(0, $repo_pos);
240 $scheduled_agent_info_1 =
"agent_pkgagent is queued to run on";
241 $scheduled_agent_info_2 =
"agent_nomos is queued to run on";
242 $scheduled_agent_info_3 =
"agent_mimetype is queued to run on";
243 $scheduled_agent_info_4 =
"agent_copyright is queued to run on";
245 $pos = strpos($out[$output_msg_count - 1], $scheduled_agent_info_1);
246 $this->assertEquals(0, $pos);
248 $pos = strpos($out[$output_msg_count - 2], $scheduled_agent_info_2);
249 $this->assertEquals(0, $pos);
251 $pos = strpos($out[$output_msg_count - 4], $scheduled_agent_info_3);
252 $this->assertEquals(0, $pos);
254 $pos = strpos($out[$output_msg_count - 6], $scheduled_agent_info_4);
255 $this->assertEquals(0, $pos, $out[$output_msg_count-4]);
259 if ($out && $out[12]) {
260 $upload_id = get_upload_id($out[12]);
262 $this->assertFalse(
true);
266 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
267 $this->assertEquals(1, $agent_status);
269 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
270 $this->assertEquals(1, $agent_status);
272 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
273 $this->assertEquals(1, $agent_status);
275 $agent_status = check_agent_status($test_dbh,
"mimetype", $upload_id);
276 $this->assertEquals(1, $agent_status);
278 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
279 $this->assertEquals(1, $agent_status);
285 $command =
"$cp2foss_path $auth -q all -A -f test/exclude -n 'test exclue dir' -d 'test des exclude dir' -X .svn ./ -v";
286 fwrite(STDOUT,
"DEBUG: Running $command\n");
287 $last = exec(
"$command 2>&1", $out, $rtn);
291 if ($out && $out[24]) {
292 $upload_id = get_upload_id($out[24]);
294 $this->assertFalse(
true);
297 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
298 $this->assertEquals(1, $agent_status);
304 $command =
"$cp2foss_path $auth -q all -A -f 'regular expression testing' -n 'test globbing dir' -d 'test des globbing' '*.php' -v";
305 fwrite(STDOUT,
"DEBUG: Running $command\n");
306 $last = exec(
"$command 2>&1", $out, $rtn);
310 if ($out && $out[18]) {
311 $upload_id = get_upload_id($out[18]);
313 $this->assertFalse(
true);
315 fwrite(STDOUT,
"Debug: upload_id is:$upload_id\n");
317 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
318 $this->assertEquals(1, $agent_status);
320 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
321 $this->assertEquals(1, $agent_status);
323 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
324 $this->assertEquals(1, $agent_status);
326 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
327 $this->assertEquals(1, $agent_status);
331 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
340 global $fossology_testconfig;
341 global $cp2foss_path;
343 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
344 $test_dbh = connect_to_DB($fossology_testconfig);
346 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
350 $command =
"$cp2foss_path $auth http://www.fossology.org/testdata/rpms/fedora/10/SRPMS/fossology-1.1.0-1.fc10.src.rpm -d 'fossology des' -f 'fossology path' -n 'test package'";
351 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
352 $last = exec(
"$command 2>&1", $out, $rtn);
359 if ($out && $out[5]) {
360 $upload_id = get_upload_id($out[5]);
362 $this->assertFalse(
true);
365 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
366 $this->assertEquals(1, $agent_status);
369 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
370 $this->assertEquals(0, $agent_status);
374 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
383 global $fossology_testconfig;
384 global $cp2foss_path;
387 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
388 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
390 $command =
"$cp2foss_path $auth -h";
391 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
392 $last = exec(
"$command 2>&1", $out, $rtn);
393 $output_msg_count = count($out);
394 $this->assertEquals(68, $output_msg_count,
"Test that the number of output lines from '$command' is 65");
399 $command =
"$cp2foss_path $auth -Q";
400 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
401 $last = exec(
"$command 2>&1", $out, $rtn);
402 $output_msg_count = count($out);
403 $this->assertEquals(10, $output_msg_count);
407 $command =
"$cp2foss_path $auth ";
408 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
409 $last = exec(
"$command 2>&1", $out, $rtn);
411 $output_msg =
"FATAL: No files to upload were specified.";
412 $this->assertEquals($output_msg, $out[0]);
414 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
424 global $fossology_testconfig;
426 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
436 public static function tearDownAfterClass()
439 global $fossology_testconfig;
440 global $scheduler_path;
441 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
444 print
"Stopping the scheduler\n";
445 $scheduler_cmd =
"$scheduler_path -k -c $fossology_testconfig";
446 fwrite(STDOUT,
"DEBUG: command is $scheduler_cmd \n");
447 exec($scheduler_cmd, $output, $return_var);
448 if ( $return_var != 0 ) {
449 print
"Error: Could not stop scheduler via '$scheduler_cmd'\n";
457 print
"End of functional tests for cp2foss \n";
test_upload_from_url()
upload from url
static setUpBeforeClass()
test_list_agent_and_others()
list agents and help msg, etc
test_upload_from_server()
upload from server