8 require_once(
"./test_common.php");
20 public $SYSCONF_DIR =
"/usr/local/etc/fossology/";
29 public $fossology_testconfig;
32 public $scheduler_path;
44 global $fossology_testconfig;
45 global $scheduler_path;
48 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
55 $fossology_testconfig = getenv(
'FOSSOLOGY_TESTCONFIG');
56 fwrite(STDOUT, __METHOD__ .
" got fossology_testconfig = '$fossology_testconfig'\n");
60 $fo_base_dir = realpath(__DIR__ .
'/../..');
61 $cp2foss_path = $fo_base_dir .
"/cli/cp2foss";
62 if (!is_executable($cp2foss_path)) {
63 print
"Error: cp2foss path '" . $cp2foss_path .
"' is not executable!\n";
66 $cp2foss_path .=
" -s ";
69 $scheduler_path = $fossology_testconfig .
"/mods-enabled/scheduler/agent/fo_scheduler";
70 if (!is_executable($scheduler_path)) {
71 print
"Error: Scheduler path '$scheduler_path' is not executable!\n";
76 $scheduler_cmd =
"$scheduler_path --daemon --reset --verbose=952 -c $fossology_testconfig";
77 fwrite(STDOUT,
"DEBUG: Starting scheduler with '$scheduler_cmd'\n");
78 exec($scheduler_cmd, $output, $return_var);
80 if ( $return_var != 0 ) {
81 print
"Error: Could not start scheduler '$scheduler_path'\n";
85 print
"\nStarting functional test for cp2foss. \n";
91 protected function setUp() : void
94 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
121 global $fossology_testconfig;
122 global $cp2foss_path;
124 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
126 $test_dbh = connect_to_DB($fossology_testconfig);
128 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
133 $command =
"$cp2foss_path $auth -q all -d 'regular expression testing' '../*.php' -v";
134 fwrite(STDOUT,
"DEBUG: Running $command\n");
135 $last = exec(
"$command 2>&1", $out, $rtn);
140 if ($out && $out[13]) {
141 $upload_id = get_upload_id($out[6]);
143 $this->assertFalse(
true);
145 fwrite(STDOUT,
"DEBUG: $upload_id \n");
147 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
148 $this->assertEquals(1, $agent_status);
150 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
151 $this->assertEquals(1, $agent_status);
153 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
154 $this->assertEquals(1, $agent_status);
156 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
157 $this->assertEquals(1, $agent_status);
160 $is_exist = check_file_uploadtree($test_dbh,
'src', $upload_id);
161 fwrite(STDOUT,
"DEBUG: is_exist is:$is_exist\n");
162 $this->assertEquals(0, $is_exist);
167 $command =
"$cp2foss_path $auth ./test_cp2foss.php";
168 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
169 $last = exec(
"$command 2>&1", $out, $rtn);
170 #print "DEBUG: output is:\n";
173 $repo_string =
"Uploading to folder: 'Software Repository'";
174 $repo_pos = strpos($out[2], $repo_string);
175 $output_msg_count = count($out);
176 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos);\n";
177 $this->assertGreaterThan(0, $repo_pos);
178 print
"DEBUG: \$this->assertEquals(4, $output_msg_count);\n";
179 $this->assertEquals(5, $output_msg_count);
182 if ($out && $out[4]) {
183 $upload_id = get_upload_id($out[4]);
184 print
"DEBUG: Upload_id is $upload_id\n";
186 print
"DEBUG: Did not get an upload_id!\n";
187 $this->assertFalse(
true);
190 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
191 $this->assertEquals(1, $agent_status);
196 $command =
"$cp2foss_path $auth ./";
197 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
198 $last = exec(
"$command 2>&1", $out, $rtn);
200 $repo_string =
"Uploading to folder: 'Software Repository'";
201 $repo_pos = strpos($out[2], $repo_string);
202 $output_msg_count = count($out);
203 $this->assertGreaterThan(0, $repo_pos);
204 $this->assertEquals(5, $output_msg_count);
207 if ($out && $out[4]) {
208 $upload_id = get_upload_id($out[4]);
210 $this->assertFalse(
true);
213 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
214 $this->assertEquals(1, $agent_status);
219 $upload_path =
"upload_path";
220 $command =
"$cp2foss_path $auth ./ -f $upload_path -d upload_des -q all -v";
221 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
222 $last = exec(
"$command 2>&1", $out, $rtn);
224 $repo_string =
"Uploading to folder: '/$upload_path'";
225 $repo_pos = strpos($out[8], $repo_string);
226 $output_msg_count = count($out);
227 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos), $repo_string\n";
228 $this->assertGreaterThan(0, $repo_pos);
229 $scheduled_agent_info_1 =
"agent_pkgagent is queued to run on";
230 $scheduled_agent_info_2 =
"agent_nomos is queued to run on";
231 $scheduled_agent_info_3 =
"agent_mimetype is queued to run on";
232 $scheduled_agent_info_4 =
"agent_copyright is queued to run on";
234 $pos = strpos($out[$output_msg_count - 1], $scheduled_agent_info_1);
235 $this->assertEquals(0, $pos);
237 $pos = strpos($out[$output_msg_count - 2], $scheduled_agent_info_2);
238 $this->assertEquals(0, $pos);
240 $pos = strpos($out[$output_msg_count - 4], $scheduled_agent_info_3);
241 $this->assertEquals(0, $pos);
243 $pos = strpos($out[$output_msg_count - 6], $scheduled_agent_info_4);
244 $this->assertEquals(0, $pos, $out[$output_msg_count-4]);
248 if ($out && $out[12]) {
249 $upload_id = get_upload_id($out[12]);
251 $this->assertFalse(
true);
255 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
256 $this->assertEquals(1, $agent_status);
258 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
259 $this->assertEquals(1, $agent_status);
261 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
262 $this->assertEquals(1, $agent_status);
264 $agent_status = check_agent_status($test_dbh,
"mimetype", $upload_id);
265 $this->assertEquals(1, $agent_status);
267 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
268 $this->assertEquals(1, $agent_status);
274 $command =
"$cp2foss_path $auth -q all -A -f test/exclude -n 'test exclue dir' -d 'test des exclude dir' -X .svn ./ -v";
275 fwrite(STDOUT,
"DEBUG: Running $command\n");
276 $last = exec(
"$command 2>&1", $out, $rtn);
280 if ($out && $out[24]) {
281 $upload_id = get_upload_id($out[24]);
283 $this->assertFalse(
true);
286 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
287 $this->assertEquals(1, $agent_status);
293 $command =
"$cp2foss_path $auth -q all -A -f 'regular expression testing' -n 'test globbing dir' -d 'test des globbing' '*.php' -v";
294 fwrite(STDOUT,
"DEBUG: Running $command\n");
295 $last = exec(
"$command 2>&1", $out, $rtn);
299 if ($out && $out[18]) {
300 $upload_id = get_upload_id($out[18]);
302 $this->assertFalse(
true);
304 fwrite(STDOUT,
"Debug: upload_id is:$upload_id\n");
306 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
307 $this->assertEquals(1, $agent_status);
309 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
310 $this->assertEquals(1, $agent_status);
312 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
313 $this->assertEquals(1, $agent_status);
315 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
316 $this->assertEquals(1, $agent_status);
320 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
329 global $fossology_testconfig;
330 global $cp2foss_path;
332 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
333 $test_dbh = connect_to_DB($fossology_testconfig);
335 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
339 $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'";
340 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
341 $last = exec(
"$command 2>&1", $out, $rtn);
348 if ($out && $out[5]) {
349 $upload_id = get_upload_id($out[5]);
351 $this->assertFalse(
true);
354 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
355 $this->assertEquals(1, $agent_status);
358 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
359 $this->assertEquals(0, $agent_status);
363 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
372 global $fossology_testconfig;
373 global $cp2foss_path;
376 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
377 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
379 $command =
"$cp2foss_path $auth -h";
380 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
381 $last = exec(
"$command 2>&1", $out, $rtn);
382 $output_msg_count = count($out);
383 $this->assertEquals(68, $output_msg_count,
"Test that the number of output lines from '$command' is 65");
388 $command =
"$cp2foss_path $auth -Q";
389 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
390 $last = exec(
"$command 2>&1", $out, $rtn);
391 $output_msg_count = count($out);
392 $this->assertEquals(10, $output_msg_count);
396 $command =
"$cp2foss_path $auth ";
397 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
398 $last = exec(
"$command 2>&1", $out, $rtn);
400 $output_msg =
"FATAL: No files to upload were specified.";
401 $this->assertEquals($output_msg, $out[0]);
403 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
413 global $fossology_testconfig;
415 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
425 public static function tearDownAfterClass()
428 global $fossology_testconfig;
429 global $scheduler_path;
430 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
433 print
"Stopping the scheduler\n";
434 $scheduler_cmd =
"$scheduler_path -k -c $fossology_testconfig";
435 fwrite(STDOUT,
"DEBUG: command is $scheduler_cmd \n");
436 exec($scheduler_cmd, $output, $return_var);
437 if ( $return_var != 0 ) {
438 print
"Error: Could not stop scheduler via '$scheduler_cmd'\n";
446 print
"End of functional tests for cp2foss \n";
test_list_agent_and_others()
list agents and help msg, etc
test_upload_from_server()
upload from server
test_upload_from_url()
upload from url
static setUpBeforeClass()