FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_fossdash_config.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © Darshan Kansagara <kansagara.darshan97@gmail.com>
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
14 
15 require_once(dirname(dirname(__FILE__)) . '/common-container.php');
16 require_once(dirname(dirname(__FILE__)) . '/common-db.php');
17 require_once(dirname(dirname(__FILE__)) . '/fossdash-config.php');
18 
22 class test_fossdash_config extends \PHPUnit\Framework\TestCase
23 {
24 
26  private $testDb;
27 
28  public $sys_conf = "";
29 
33  protected function setUpDb()
34  {
35  global $sys_conf;
36 
37  $this->testDb = new TestPgDb("fosslibtest");
38  $sys_conf = $this->testDb->getFossSysConf();
39  }
40 
47  function testConfigInit()
48  {
49  $this->setUpDb();
50  global $sys_conf;
51  FossdashConfigInit($sys_conf, $SysConf);
52  $this->assertEquals("0", $SysConf['FOSSDASHCONFIG']['FossdashEnableDisable']);
53  $this->assertEquals("* * * * *", $SysConf['FOSSDASHCONFIG']['FossDashScriptCronSchedule']);
54  $this->tearDownDb();
55  }
56 
60  protected function tearDownDb()
61  {
62  if (!is_callable('pg_connect')) {
63  return;
64  }
65  $this->testDb->fullDestruct();
66  $this->testDb = null;
67  }
68 
72  public function test_check_fossdash_url()
73  {
74  foreach (array('http://localhost:8086/write?db=fossology_db'=>true,
75  'http://influxdb:8086/write?db=fossology_db'=>true,
76  'http://127.0.0.1:8086/write?db=fossology_db'=>true,
77  'ssh://127.0.0.1:8086'=>false,) as $url=>$correct) {
78  $this->assertEquals(check_fossdash_url($url),$correct,$message="result for URL $url is false");
79  print('.');
80  }
81  }
82 
86  public function test_check_cron_job_inteval()
87  {
88  foreach (array('* * * * *'=>true,
89  '1 1 * 1 *'=>true,
90  '*/1 * * * *'=>true,
91  'abbkbkb'=>false,
92  '* * * * * 23567'=>false,
93  '1 1 1 1 1 1'=>false) as $cron=>$correct) {
94  $this->assertEquals(check_cron_job_inteval($cron),$correct,$message="result for CRON $cron is false");
95  print('.');
96  }
97  }
98 
103  {
104  foreach (array('fossology_instance_1'=>true,
105  'fossology-instance-1'=>true,
106  'instance=1'=>false,
107  ''=>false,
108  'fossology instance 1'=>false,
109  'instance1'=>true) as $instance_name=>$correct) {
110  $this->assertEquals(check_fossology_instance_name($instance_name),$correct,$message="result for CRON $instance_name is false");
111  print('.');
112  }
113  }
114 
119  {
120  foreach (array('22'=>true,
121  '1'=>true,
122  '0'=>true,
123  'ghgl'=>false,
124  'one'=>false) as $clening_interval=>$correct) {
125  $this->assertEquals(check_fossdash_cleaning($clening_interval),$correct,$message="result for CRON $clening_interval is false");
126  print('.');
127  }
128  }
129 
133  public function test_check_fossdash_config()
134  {
135  foreach (array('sfksb ghs 124 () * * ?'=>true,
136  'drop table sysconfig'=>false,
137  'alter table sysconfig'=>false,
138  'INSERT INTO sysconfig'=>false) as $metric=>$correct) {
139  $this->assertEquals(check_fossdash_config($metric),$correct,$message="result for metric $metric is false");
140  print('.');
141  }
142  }
143 }
144 
test_check_cron_job_inteval()
check cron job inteval
test_check_fossdash_cleaning()
check fossdash cleaning days
test_check_fossology_instance_name()
check fossology instance name
setUpDb()
initialization with db
test_check_fossdash_url()
check fossdash url
testConfigInit()
test for ConfigInit() after ConfigInit() is executed, we can get some sysconfig information,...
test_check_fossdash_config()
check fossdash metric config
check_fossdash_url($url)
Check if the fossdash url is valid.
check_fossology_instance_name($instance_name)
Check if the fossology instance name is valid.
check_cron_job_inteval($cron_interval)
Check if the cron job schedule interval is valid.
check_fossdash_config($config_str)
Check if given config string does not contains any DB update or drop related commands.
FossdashConfigInit($sysconfdir, &$SysConf)
Initialize the fossdash configuration after bootstrap().
check_fossdash_cleaning($cleaning_days)
Check if cleaning_days is valid or not.