17 if (!function_exists(
'Traceback_uri'))
20 return 'Traceback_uri_if_desired';
35 private $uploadPermDao;
37 protected function setUp() :
void
39 $this->testDb =
new TestPgDb(
"ninkaSched".time());
40 $this->
dbManager = $this->testDb->getDbManager();
43 $logger =
new Logger(
"NinkaSchedulerTest");
44 $this->uploadPermDao = \Mockery::mock(UploadPermissionDao::class);
48 protected function tearDown() :
void
50 $this->testDb->fullDestruct();
53 $this->licenseDao =
null;
56 private function runNinka($uploadId)
58 $sysConf = $this->testDb->getFossSysConf();
62 $agentDir = dirname(dirname(__DIR__));
63 $execDir =
"$agentDir/agent";
64 system(
"install -D $agentDir/VERSION $sysConf/mods-enabled/$agentName/VERSION");
66 $pipeFd = popen(
"echo $uploadId | $execDir/$agentName -c $sysConf --scheduler_start",
"r");
67 $this->assertTrue($pipeFd !==
false,
'running ninka failed');
70 while (($buffer = fgets($pipeFd, 4096)) !==
false) {
73 $retCode = pclose($pipeFd);
75 unlink(
"$sysConf/mods-enabled/$agentName/VERSION");
76 rmdir(
"$sysConf/mods-enabled/$agentName");
77 rmdir(
"$sysConf/mods-enabled");
79 return array($output,$retCode);
82 private function setUpRepo()
84 $sysConf = $this->testDb->getFossSysConf();
86 $confFile = $sysConf.
"/fossology.conf";
87 system(
"touch ".$confFile);
88 $config =
"[FOSSOLOGY]\ndepth = 0\npath = $sysConf/repo\n";
89 file_put_contents($confFile, $config);
91 $testRepoDir = dirname(dirname(dirname(__DIR__))).
"/lib/php/Test/";
92 system(
"cp -a $testRepoDir/repo $sysConf/");
95 private function rmRepo()
97 $sysConf = $this->testDb->getFossSysConf();
98 system(
"rm $sysConf/repo -rf");
100 unlink($sysConf.
"/fossology.conf");
103 private function setUpTables()
105 $this->testDb->createPlainTables(array(
'upload',
'uploadtree',
'license_ref',
'license_file',
'highlight',
'agent',
'pfile',
'ars_master'),
false);
106 $this->testDb->createSequences(array(
'agent_agent_pk_seq',
'pfile_pfile_pk_seq',
'upload_upload_pk_seq',
'nomos_ars_ars_pk_seq',
'license_file_fl_pk_seq',
'license_ref_rf_pk_seq'),
false);
107 $this->testDb->createViews(array(
'license_file_ref'),
false);
108 $this->testDb->createConstraints(array(
'agent_pkey',
'pfile_pkey',
'upload_pkey_idx',
'FileLicense_pkey',
'rf_pkpk'),
false);
109 $this->testDb->alterTables(array(
'agent',
'pfile',
'upload',
'ars_master',
'license_file',
'highlight',
'license_ref'),
false);
110 $this->testDb->createInheritedTables();
111 $this->testDb->insertData(array(
'pfile',
'upload',
'uploadtree_a'),
false);
112 $this->testDb->insertData_license_ref();
113 $this->testDb->resetSequenceAsMaxOf(
'license_ref_rf_pk_seq',
'license_ref',
'rf_pk');
117 public function testRun()
119 $this->setUpTables();
122 list($output,$retCode) = $this->runNinka($uploadId=1);
126 $this->assertEquals($retCode, 0,
'ninka failed: '.$output);
128 $bounds = $this->uploadDao->getParentItemBounds($uploadId);
129 $matches = $this->licenseDao->getAgentFileLicenseMatches($bounds);
131 $this->assertEquals($expected=6, count($matches));
133 foreach($matches as $licenseMatch) {
135 $matchedLicense = $licenseMatch->getLicenseRef();
137 switch ($licenseMatch->getFileId()) {
140 $expectedLicense =
"GPL-3.0+";
143 $expectedLicense =
"UnclassifiedLicense";
146 $expectedLicense =
"No_license_found";
150 $this->assertEquals($expectedLicense, $matchedLicense->getShortName(),
"unexpected license for fileId ".$licenseMatch->getFileId());
153 $agentRef = $licenseMatch->getAgentRef();
154 $this->assertEquals($agentRef->getAgentName(),
"ninka");
Traceback_uri()
Get the URI without query to this location.
fo_dbManager * dbManager
fo_dbManager object