FOSSology  4.4.0
Open Source License Compliance by Open Source Software
SchedulerTestRunnerCli.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Reuser\Test;
9 
11 
12 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
13 include_once(__DIR__.'/SchedulerTestRunner.php');
14 
20 {
24  private $testDb;
25 
26  public function __construct(TestPgDb $testDb)
27  {
28  $this->testDb = $testDb;
29  }
30 
31  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
32  {
33  $sysConf = $this->testDb->getFossSysConf();
34 
35  $agentName = "reuser";
36 
37  $agentDir = dirname(dirname(__DIR__));
38  $execDir = "$agentDir/agent";
39  system("install -D $agentDir/VERSION $sysConf/mods-enabled/$agentName/VERSION");
40 
41  $pipeFd = popen($cmd = "echo $uploadId | $execDir/$agentName --userID=$userId --groupID=$groupId --jobId=$jobId --scheduler_start -c $sysConf $args", "r");
42  $success = $pipeFd !== false;
43 
44  $output = "";
45  $retCode = -1;
46  if ($success) {
47  while (($buffer = fgets($pipeFd, 4096)) !== false) {
48  $output .= $buffer;
49  }
50  $retCode = pclose($pipeFd);
51  } else {
52  print "failed opening pipe to $cmd";
53  }
54 
55  unlink("$sysConf/mods-enabled/$agentName/VERSION");
56  rmdir("$sysConf/mods-enabled/$agentName");
57  rmdir("$sysConf/mods-enabled");
58 
59  return array($success, $output, $retCode);
60  }
61 }
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Function to run agent from scheduler.
Namespace to hold test cases for Reuser agent.