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 =
"/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 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 =
"--user fossy --password fossy -c $fossology_testconfig";
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 #print "DEBUG: output is:\n"; 116 fwrite(STDOUT,
"DEBUG: Sleeping for 10 seconds (why?), because you have to wait for all the scheduled agents are finished.\n");
119 $repo_string =
"Uploading to folder: 'Software Repository'";
120 $repo_pos = strpos($out[1], $repo_string);
121 $output_msg_count = count($out);
122 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos);\n";
123 $this->assertGreaterThan(0, $repo_pos);
124 print
"DEBUG: \$this->assertEquals(4, $output_msg_count);\n";
125 $this->assertEquals(4, $output_msg_count);
128 if ($out && $out[3]) {
129 $upload_id = get_upload_id($out[3]);
130 print
"DEBUG: Upload_id is $upload_id\n";
133 print
"DEBUG: Did not get an upload_id!\n";
134 $this->assertFalse(TRUE);
137 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
138 $this->assertEquals(1, $agent_status);
143 $command =
"$cp2foss_path $auth ./";
144 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
145 $last = exec(
"$command 2>&1", $out, $rtn);
146 print
"DEBUG: output is:\n";
148 print
"DEBUG: Sleeping for 10 seconds (why?), because you have to wait for all the scheduled agents are finished.\n";
151 $repo_string =
"Uploading to folder: 'Software Repository'";
152 $repo_pos = strpos($out[1], $repo_string);
153 $output_msg_count = count($out);
154 $this->assertGreaterThan(0, $repo_pos);
155 $this->assertEquals(4, $output_msg_count);
158 if ($out && $out[3]) {
159 $upload_id = get_upload_id($out[3]);
160 }
else $this->assertFalse(TRUE);
162 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
163 $this->assertEquals(1, $agent_status);
168 $upload_path =
"upload_path";
169 $command =
"$cp2foss_path $auth ./ -f $upload_path -d upload_des -q all -v";
170 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
171 $last = exec(
"$command 2>&1", $out, $rtn);
174 $repo_string =
"Uploading to folder: '/$upload_path'";
175 $repo_pos = strpos($out[7], $repo_string);
176 $output_msg_count = count($out);
177 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos)\n";
178 $this->assertGreaterThan(0, $repo_pos);
179 $scheduled_agent_info_1 =
"agent_pkgagent is queued to run on";
180 $scheduled_agent_info_2 =
"agent_nomos is queued to run on";
181 $scheduled_agent_info_3 =
"agent_mimetype is queued to run on";
182 $scheduled_agent_info_4 =
"agent_copyright is queued to run on";
184 $pos = strpos($out[$output_msg_count - 1], $scheduled_agent_info_1);
185 $this->assertEquals(0, $pos);
187 $pos = strpos($out[$output_msg_count - 2], $scheduled_agent_info_2);
188 $this->assertEquals(0, $pos);
190 $pos = strpos($out[$output_msg_count - 3], $scheduled_agent_info_3);
191 $this->assertEquals(0, $pos);
193 $pos = strpos($out[$output_msg_count - 4], $scheduled_agent_info_4);
194 $this->assertEquals(0, $pos);
198 if ($out && $out[11]) {
199 $upload_id = get_upload_id($out[11]);
200 }
else $this->assertFalse(TRUE);
202 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
203 $this->assertEquals(1, $agent_status);
205 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
206 $this->assertEquals(1, $agent_status);
208 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
209 $this->assertEquals(1, $agent_status);
211 $agent_status = check_agent_status($test_dbh,
"mimetype", $upload_id);
212 $this->assertEquals(1, $agent_status);
214 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
215 $this->assertEquals(1, $agent_status);
221 $command =
"$cp2foss_path $auth -q all -A -f test/exclude -n 'test exclue dir' -d 'test des exclude dir' -X .svn ./ -v";
222 fwrite(STDOUT,
"DEBUG: Running $command\n");
223 $last = exec(
"$command 2>&1", $out, $rtn);
228 if ($out && $out[23]) {
229 $upload_id = get_upload_id($out[23]);
230 }
else $this->assertFalse(TRUE);
232 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
233 $this->assertEquals(1, $agent_status);
237 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
242 public static function tearDownAfterClass() {
244 global $fossology_testconfig;
245 global $scheduler_path;
248 print
"Stopping the scheduler\n";
249 $scheduler_cmd =
"$scheduler_path -k -c $fossology_testconfig";
250 exec($scheduler_cmd, $output, $return_var);
251 if ( $return_var != 0 ) {
252 print
"Error: Could not stop scheduler via '$scheduler_cmd'\n";
259 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