FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ft_DelagentTest.php
1 <?php
2 /*
3  Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/cli/tests/test_common.php');
20 require_once (__DIR__ . "/../../../testing/db/createEmptyTestEnvironment.php");
21 
27 class ft_DelagentTest extends \PHPUnit\Framework\TestCase {
28 
29  public $SYSCONF_DIR;
30  public $DB_NAME;
31  public $PG_CONN;
32  public $DB_COMMAND;
33 
38  function upload_testdata(){
39  global $SYSCONF_DIR;
40  $auth = "--user fossy --password fossy -c $SYSCONF_DIR";
42  $out = "";
43  $pos = 0;
44  $upload_path = "upload_path";
45  $command = "cp2foss $auth ../../../pkgagent/agent_tests/testdata/fossology-1.2.0-1.el5.i386.rpm -f $upload_path -d upload_des -q all -v";
46  $last = exec("$command 2>&1", $out, $rtn);
47  sleep(10);
48  $repo_string = "Uploading to folder: '/$upload_path'";
49  $repo_pos = strpos($out[7], $repo_string);
50  $output_msg_count = count($out);
51  $this->assertGreaterThan(0, $repo_pos);
52  $scheduled_agent_info_1 = "agent_pkgagent is queued to run on";
53  $scheduled_agent_info_2 = "agent_nomos is queued to run on";
54  $scheduled_agent_info_3 = "agent_mimetype is queued to run on";
55  $scheduled_agent_info_4 = "agent_copyright is queued to run on";
56  $pos = false;
57  $pos = strpos($out[$output_msg_count - 1], $scheduled_agent_info_1);
58  $this->assertEquals(0, $pos);
59  $pos = false;
60  $pos = strpos($out[$output_msg_count - 2], $scheduled_agent_info_2);
61  $this->assertEquals(0, $pos);
62  $pos = false;
63  $pos = strpos($out[$output_msg_count - 3], $scheduled_agent_info_3);
64  $this->assertEquals(0, $pos);
65  $pos = false;
66  $pos = strpos($out[$output_msg_count - 4], $scheduled_agent_info_4);
67  $this->assertEquals(0, $pos);
68  $upload_id = 0;
70  if ($out && $out[11]) {
71  $upload_id = get_upload_id($out[11]);
72  } else {
73  $this->assertFalse(true);
74  }
75  $agent_status = 0;
76  $agent_status = check_agent_status("ununpack", $upload_id);
77  $this->assertEquals(1, $agent_status);
78  $agent_status = 0;
79  $agent_status = check_agent_status("copyright", $upload_id);
80  $this->assertEquals(1, $agent_status);
81  $agent_status = 0;
82  $agent_status = check_agent_status("nomos", $upload_id);
83  $this->assertEquals(1, $agent_status);
84  $agent_status = 0;
85  $agent_status = check_agent_status("mimetype", $upload_id);
86  $this->assertEquals(1, $agent_status);
87  $agent_status = 0;
88  $agent_status = check_agent_status("pkgagent", $upload_id);
89  $this->assertEquals(1, $agent_status);
90  }
91 
92  /* initialization */
93  protected function setUp() {
94  global $SYSCONF_DIR;
95  global $DB_COMMAND;
96  global $DB_NAME;
97  global $REPO_NAME;
98 
99  $cwd = getcwd();
100  list($test_name, $SYSCONF_DIR, $DB_NAME, $PG_CONN) = setupTestEnv($cwd, "delagent", false);
101 
102  $REPO_NAME = "testDbRepo".$test_name;
103  add_user();
104  replace_repo();
105  scheduler_operation();
106  $this->upload_testdata();
107  }
108 
116  function test_delagentu(){
117  global $EXE_PATH;
118  global $PG_CONN;
119 
120  $expected = "";
121 
122  $sql = "SELECT upload_pk, upload_filename FROM upload ORDER BY upload_pk;";
123  $result = pg_query($PG_CONN, $sql);
124  if (pg_num_rows($result) > 0){
125  $row = pg_fetch_assoc($result);
126  $expected = $row["upload_pk"] . " :: ". $row["upload_filename"];
127  }
128  pg_free_result($result);
129  /* the file is one executable file */
130  $command = "$EXE_PATH -u -n fossy -p fossy";
131  exec($command, $out, $rtn);
132  //print_r($out);
133  $this->assertStringStartsWith($expected, $out[1]);
134  }
135 
144  global $EXE_PATH;
145  global $PG_CONN;
146 
147  $expected = "";
148 
149  add_user("testuser", "testuser");
150  $sql = "SELECT upload_pk, upload_filename FROM upload ORDER BY upload_pk;";
151  $result = pg_query($PG_CONN, $sql);
152  if (pg_num_rows($result) > 0){
153  $row = pg_fetch_assoc($result);
154  $expected = $row["upload_pk"] . " :: ". $row["upload_filename"];
155  }
156  pg_free_result($result);
157  /* the file is one executable file */
158  $command = "$EXE_PATH -u -n testuser -p testuser";
159  exec($command, $out, $rtn);
160  //print_r($out);
161  $this->assertStringStartsWith($expected, $out[1]);
162  }
163 
167  protected function tearDown() {
168  rollback_repo(); // rollback the repo dir in ununpack.conf and wget_agent.conf to the default
169  drop_db();
170  print "End up functional test for cp2foss \n";
171  }
172 
173 }
174 
175 
test_delagentu()
test delagent -u
add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
test_delagentu_wronguser()
test delagent -u with wrong user
test delagent cli
tearDown()
clean the env
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321
upload_testdata()
upload testdata prepare testdata for delagent, upload one tar file and schedule all agents ...