12 require_once (__DIR__ .
"/../../../testing/db/createEmptyTestEnvironment.php");
20 public $EXE_PATH =
"";
22 public $DB_COMMAND =
"";
27 protected function setUp() :
void {
35 list($test_name, $DB_CONF, $DB_NAME, $PG_CONN) = setupTestEnv($cwd,
"delagent",
false);
37 $EXE_PATH =
'../../agent/delagent';
41 if(file_exists($EXE_PATH))
43 $usage =
'Usage: ../../agent/delagent [options]';
44 $usageL =
' -f :: List folder IDs.';
48 $this->assertFileExists($EXE_PATH,
49 $message =
'FATAL: cannot find executable file, stop testing\n');
52 $EXE_PATH .=
" -c $DB_CONF";
53 $last = exec(
"$EXE_PATH -h 2>&1", $out, $rtn);
54 $this->assertEquals($usage, $out[0]);
55 $this->assertEquals($usageL, $out[6]);
73 $db_array = parse_ini_file(
"$DB_CONF/Db.conf");
74 $db_user = $db_array[
"user"];
76 exec(
"gunzip -c ../testdata/testdb_all.gz | psql -U $db_user -d $DB_NAME >/dev/null");
78 $sql =
"SELECT upload_pk, upload_filename FROM upload ORDER BY upload_pk;";
79 $result = pg_query($PG_CONN, $sql);
80 if (pg_num_rows($result) > 0){
81 $row = pg_fetch_assoc($result);
82 $expected = $row[
"upload_pk"] .
" :: ". $row[
"upload_filename"];
84 pg_free_result($result);
86 $command =
"$EXE_PATH -u -n fossy -p fossy";
87 exec($command, $out, $rtn);
89 $this->assertStringStartsWith($expected, $out[1]);
109 $db_array = parse_ini_file(
"$DB_CONF/Db.conf");
110 $db_user = $db_array[
"user"];
112 exec(
"gunzip -c ../testdata/testdb_all.gz | psql -U $db_user -d $DB_NAME >/dev/null");
114 $sql =
"SELECT folder_pk,parent,name,description,upload_pk FROM folderlist ORDER BY name,parent,folder_pk;";
115 $result = pg_query($PG_CONN, $sql);
116 if (pg_num_rows($result) > 0){
117 $row = pg_fetch_assoc($result);
118 $expected =
" -- :: Contains: " . $row[
"name"];
120 pg_free_result($result);
121 $command =
"$EXE_PATH -f -n fossy -p fossy";
122 exec($command, $out, $rtn);
123 #print $expected . "\n";
124 #print $out[1] . "\n";
125 $this->assertStringStartsWith($expected, $out[2]);
141 $expected =
"The upload '2' is deleted by the user 'fossy'.";
143 $db_array = parse_ini_file(
"$DB_CONF/Db.conf");
144 $db_user = $db_array[
"user"];
146 exec(
"gunzip -c ../testdata/testdb_all.gz | psql -U $db_user -d $DB_NAME >/dev/null");
147 $sql =
"UPDATE upload SET user_fk = 3;";
148 $result = pg_query($PG_CONN, $sql);
149 pg_free_result($result);
151 $command =
"$EXE_PATH -U 2 -n fossy -p fossy";
152 exec($command, $out, $rtn);
153 #print $expected . "\n";
154 #print $out[1] . "\n";
155 $sql =
"SELECT upload_fk, uploadtree_pk FROM bucket_container, uploadtree WHERE uploadtree_fk = uploadtree_pk AND upload_fk = 2;";
156 $result = pg_query($PG_CONN, $sql);
157 if (pg_num_rows($result) > 0){
158 $this->assertFalse(
"bucket_container records not deleted!");
160 pg_free_result($result);
162 $this->assertStringStartsWith($expected, $out[0]);
176 exec(
"$DB_COMMAND -d $DB_NAME");
177 exec(
"rm -rf $DB_CONF");
test the delagent agent thru command line.
testDelagentf()
test delagent -f
testDelagentu()
test delagent -u
testDelagentUpload()
test delagent -U 2
list_t type structure used to keep various lists. (e.g. there are multiple lists).