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 =
"/usr/local/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 $PG_CONN = 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 =
"--username fossy --password fossy -c $fossology_testconfig -s ";
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 $repo_string =
"Uploading to folder: 'Software Repository'";
104 $repo_pos = strpos($out[1], $repo_string);
105 $output_msg_count = count($out);
106 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos);\n";
107 $this->assertGreaterThan(0, $repo_pos);
108 print
"DEBUG: \$this->assertEquals(4, $output_msg_count);\n";
109 $this->assertEquals(4, $output_msg_count);
112 if ($out && $out[3]) {
113 $upload_id = get_upload_id($out[3]);
114 print
"DEBUG: Upload_id is $upload_id\n";
117 print
"DEBUG: Did not get an upload_id!\n";
118 $this->assertFalse(TRUE);
121 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
122 $this->assertEquals(1, $agent_status);
127 $command =
"$cp2foss_path $auth ./";
128 fwrite(STDOUT,
"DEBUG: test_upload_from_server executing '$command'\n");
129 $last = exec(
"$command 2>&1", $out, $rtn);
130 $repo_string =
"Uploading to folder: 'Software Repository'";
131 $repo_pos = strpos($out[1], $repo_string);
132 $output_msg_count = count($out);
133 $this->assertGreaterThan(0, $repo_pos);
134 $this->assertEquals(4, $output_msg_count);
137 if ($out && $out[3]) {
138 $upload_id = get_upload_id($out[3]);
139 }
else $this->assertFalse(TRUE);
141 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
142 $this->assertEquals(1, $agent_status);
147 $upload_path =
"upload_path";
148 $command =
"$cp2foss_path $auth ./ -f $upload_path -d upload_des -q all -v";
149 fwrite(STDOUT,
"DEBUG: Executing '$command'\n");
150 $last = exec(
"$command 2>&1", $out, $rtn);
151 $repo_string =
"Uploading to folder: '/$upload_path'";
152 $repo_pos = strpos($out[7], $repo_string);
153 $output_msg_count = count($out);
154 print
"DEBUG: \$this->assertGreaterThan(0, $repo_pos)\n";
155 $this->assertGreaterThan(0, $repo_pos);
156 $scheduled_agent_info_1 =
"agent_pkgagent is queued to run on";
157 $scheduled_agent_info_2 =
"agent_nomos is queued to run on";
158 $scheduled_agent_info_3 =
"agent_monk is queued to run on";
159 $scheduled_agent_info_4 =
"agent_mimetype is queued to run on";
160 $scheduled_agent_info_5 =
"agent_copyright is queued to run on";
162 $pos = strpos($out[$output_msg_count - 1], $scheduled_agent_info_1);
163 $this->assertEquals(0, $pos);
165 $pos = strpos($out[$output_msg_count - 2], $scheduled_agent_info_2);
166 $this->assertEquals(0, $pos);
168 $pos = strpos($out[$output_msg_count - 3], $scheduled_agent_info_3);
169 $this->assertEquals(0, $pos);
171 $pos = strpos($out[$output_msg_count - 4], $scheduled_agent_info_4);
172 $this->assertEquals(0, $pos);
174 $pos = strpos($out[$output_msg_count - 5], $scheduled_agent_info_5);
175 $this->assertEquals(0, $pos);
179 if ($out && $out[11]) {
180 $upload_id = get_upload_id($out[11]);
181 }
else $this->assertFalse(TRUE);
183 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
184 $this->assertEquals(1, $agent_status);
186 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
187 $this->assertEquals(1, $agent_status);
189 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
190 $this->assertEquals(1, $agent_status);
192 $agent_status = check_agent_status($test_dbh,
"mimetype", $upload_id);
193 $this->assertEquals(1, $agent_status);
195 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
196 $this->assertEquals(1, $agent_status);
202 $command =
"$cp2foss_path $auth -q all -A -f test/exclude -n 'test exclue dir' -d 'test des exclude dir' -X .svn ./ -v";
203 fwrite(STDOUT,
"DEBUG: Running $command\n");
204 $last = exec(
"$command 2>&1", $out, $rtn);
207 if ($out && $out[23]) {
208 $upload_id = get_upload_id($out[23]);
209 }
else $this->assertFalse(TRUE);
211 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
212 $this->assertEquals(1, $agent_status);
216 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
221 public static function tearDownAfterClass() {
223 global $fossology_testconfig;
224 global $scheduler_path;
227 print
"Stopping the scheduler\n";
228 $scheduler_cmd =
"$scheduler_path -k -c $fossology_testconfig";
229 exec($scheduler_cmd, $output, $return_var);
230 if ( $return_var != 0 ) {
231 print
"Error: Could not stop scheduler via '$scheduler_cmd'\n";
238 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.