12 require_once(
"./test_common.php");
27 public $fossology_testconfig;
30 public $scheduler_path;
41 global $fossology_testconfig;
42 global $scheduler_path;
46 $fossology_testconfig = getenv(
'FOSSOLOGY_TESTCONFIG');
48 if (empty($fossology_testconfig)) $fossology_testconfig =
"/etc/fossology/";
49 fwrite(STDOUT, __METHOD__ .
" got fossology_testconfig = '$fossology_testconfig'\n");
51 $cp2foss_path =
"cp2foss";
54 $scheduler_path = $fossology_testconfig .
"/mods-enabled/scheduler/agent/fo_scheduler";
55 if (!is_executable($scheduler_path)) {
56 print
"Error: Scheduler path '$scheduler_path' is not executable!\n";
61 $scheduler_cmd =
"$scheduler_path --daemon --reset --verbose=952 -c $fossology_testconfig";
62 print
"DEBUG: Starting scheduler with '$scheduler_cmd'\n";
63 exec($scheduler_cmd, $output, $return_var);
65 if ( $return_var != 0 ) {
66 print
"Error: Could not start scheduler '$scheduler_path'\n";
71 connect_to_DB($fossology_testconfig);
74 print
"\nStarting functional test for cp2foss. \n";
88 global $fossology_testconfig;
92 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
96 $auth =
"--user fossy --password fossy -c $fossology_testconfig";
100 $command =
"$cp2foss_path $auth ./test_cp2foss.php";
101 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
102 $last = exec(
"$command 2>&1", $out, $rtn);
103 #print "DEBUG: output is:\n";
105 fwrite(STDOUT,
"DEBUG: Sleeping for 10 seconds (why?), because you have to wait for all the scheduled agents are finished.\n");
108 $repo_string =
"Uploading to folder: 'Software Repository'";
109 $repo_pos = strpos($out[1], $repo_string);
110 $output_msg_count = count($out);
111 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos);\n";
112 $this->assertGreaterThan(0, $repo_pos);
113 print
"DEBUG: \$this->assertEquals(4, $output_msg_count);\n";
114 $this->assertEquals(4, $output_msg_count);
117 if ($out && $out[3]) {
118 $upload_id = get_upload_id($out[3]);
119 print
"DEBUG: Upload_id is $upload_id\n";
122 print
"DEBUG: Did not get an upload_id!\n";
123 $this->assertFalse(TRUE);
126 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
127 $this->assertEquals(1, $agent_status);
132 $command =
"$cp2foss_path $auth ./";
133 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
134 $last = exec(
"$command 2>&1", $out, $rtn);
135 print
"DEBUG: output is:\n";
137 print
"DEBUG: Sleeping for 10 seconds (why?), because you have to wait for all the scheduled agents are finished.\n";
140 $repo_string =
"Uploading to folder: 'Software Repository'";
141 $repo_pos = strpos($out[1], $repo_string);
142 $output_msg_count = count($out);
143 $this->assertGreaterThan(0, $repo_pos);
144 $this->assertEquals(4, $output_msg_count);
147 if ($out && $out[3]) {
148 $upload_id = get_upload_id($out[3]);
149 }
else $this->assertFalse(TRUE);
151 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
152 $this->assertEquals(1, $agent_status);
157 $upload_path =
"upload_path";
158 $command =
"$cp2foss_path $auth ./ -f $upload_path -d upload_des -q all -v";
159 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
160 $last = exec(
"$command 2>&1", $out, $rtn);
163 $repo_string =
"Uploading to folder: '/$upload_path'";
164 $repo_pos = strpos($out[7], $repo_string);
165 $output_msg_count = count($out);
166 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos)\n";
167 $this->assertGreaterThan(0, $repo_pos);
168 $scheduled_agent_info_1 =
"agent_pkgagent is queued to run on";
169 $scheduled_agent_info_2 =
"agent_nomos is queued to run on";
170 $scheduled_agent_info_3 =
"agent_mimetype is queued to run on";
171 $scheduled_agent_info_4 =
"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);
187 if ($out && $out[11]) {
188 $upload_id = get_upload_id($out[11]);
189 }
else $this->assertFalse(TRUE);
191 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
192 $this->assertEquals(1, $agent_status);
194 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
195 $this->assertEquals(1, $agent_status);
197 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
198 $this->assertEquals(1, $agent_status);
200 $agent_status = check_agent_status($test_dbh,
"mimetype", $upload_id);
201 $this->assertEquals(1, $agent_status);
203 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
204 $this->assertEquals(1, $agent_status);
210 $command =
"$cp2foss_path $auth -q all -A -f test/exclude -n 'test exclue dir' -d 'test des exclude dir' -X .svn ./ -v";
211 fwrite(STDOUT,
"DEBUG: Running $command\n");
212 $last = exec(
"$command 2>&1", $out, $rtn);
217 if ($out && $out[23]) {
218 $upload_id = get_upload_id($out[23]);
219 }
else $this->assertFalse(TRUE);
221 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
222 $this->assertEquals(1, $agent_status);
226 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
231 public static function tearDownAfterClass() {
233 global $fossology_testconfig;
234 global $scheduler_path;
237 print
"Stopping the scheduler\n";
238 $scheduler_cmd =
"$scheduler_path -k -c $fossology_testconfig";
239 exec($scheduler_cmd, $output, $return_var);
240 if ( $return_var != 0 ) {
241 print
"Error: Could not stop scheduler via '$scheduler_cmd'\n";
248 print
"End of functional tests for cp2foss \n";
test_upload_from_server()
upload from server
static setUpBeforeClass()
add_user($User, $Desc, $Hash, $Perm, $Email, $Email_notify, $Upload_visibility, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.