FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
SchedulerTestRunnerCli.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
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 
20 
22 
23 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
24 include_once(__DIR__.'/SchedulerTestRunner.php');
25 
32 {
34  private $testDb;
35 
36  public function __construct(TestPgDb $testDb)
37  {
38  $this->testDb = $testDb;
39  }
40 
50  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
51  {
52  $sysConf = $this->testDb->getFossSysConf();
53 
54  $agentName = "deciderjob";
55 
56  $agentDir = dirname(dirname(__DIR__));
57  $execDir = "$agentDir/agent";
58  system("install -D $agentDir/VERSION $sysConf/mods-enabled/$agentName/VERSION");
59 
60  $pipeFd = popen($cmd = "echo $uploadId | $execDir/$agentName --userID=$userId --groupID=$groupId --jobId=$jobId --scheduler_start -c $sysConf $args", "r");
61  $success = $pipeFd !== false;
62 
63  $output = "";
64  $retCode = -1;
65  if ($success) {
66  while (($buffer = fgets($pipeFd, 4096)) !== false) {
67  $output .= $buffer;
68  }
69  $retCode = pclose($pipeFd);
70  } else {
71  print "failed opening pipe to $cmd";
72  }
73 
74  unlink("$sysConf/mods-enabled/$agentName/VERSION");
75  rmdir("$sysConf/mods-enabled/$agentName");
76  rmdir("$sysConf/mods-enabled");
77 
78  return array($success, $output, $retCode);
79  }
80 }
Namespace for decider job test cases.
Interface for scheduler. Called by test case.
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Mock as agent was called from CLI.