public function testGetMountPoint() { $diskUsage = new DiskUsage(new DI()); $this->assertEquals('/', $diskUsage->getMountPoint(), 'DiskUsage::getMountPoint default value test failed!'); $diskUsage->setMountPoint('/home'); $this->assertEquals('/home', $diskUsage->getMountPoint(), 'DiskUsage::getMountPoint test failed!'); }
public function testRun() { /* @var CommandRunner $fakeCmdRunner1 */ $fakeCmdRunner1 = Stub::make('\\AWSCustomMetric\\CommandRunner', ['execute' => function () { }, 'getReturnValue' => '56']); /* @var CommandRunner $fakeCmdRunner2 */ $fakeCmdRunner2 = Stub::make('\\AWSCustomMetric\\CommandRunner', ['execute' => function () { }, 'getReturnCode' => 0, 'getOutput' => ['MemTotal: 10000 kB', 'MemFree: 2000 kB', 'MemAvailable: 419980 kB', 'Buffers: 1000 kB', 'Cached: 1000 kB', 'SwapCached: 0 kB', 'Active: 526652 kB', 'Inactive: 164928 kB', 'SwapTotal: 10000 kB', 'SwapFree: 9000 kB']]); $diObj1 = new DI(); $diObj1->setCommandRunner($fakeCmdRunner1); $diObj2 = new DI(); $diObj2->setCommandRunner($fakeCmdRunner2); $plugin1 = new DiskUsage($diObj1); $plugin2 = new MemoryUsage($diObj2); $testObj = new Sender('fakekey', 'fakesecret', 'fakeregion', $fakeCmdRunner1, 'testInstance', 'testns'); $testObj->addPlugin([$plugin1, $plugin2]); $testObj->run(); $actualStr = file_get_contents(rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'cloud_watch_client.txt'); $exceptedStr = ''; $exceptedStr .= json_encode($this->tester->getMetricDataArray($plugin1->getMetrics(), 'testInstance', 'testns')) . "\n"; $exceptedStr .= json_encode($this->tester->getMetricDataArray($plugin2->getMetrics(), 'testInstance', 'testns')) . "\n"; $this->assertEquals($exceptedStr, $actualStr, 'Sender::run default test failed!'); $plugin3 = new DiskUsage($diObj1, 'Test/System', '* * * * *'); $plugin4 = new MemoryUsage($diObj2, 'Test/System', '*/' . (date('i') + 1) . ' * * * *'); $testObj2 = new Sender('fakekey', 'fakesecret', 'fakeregion', $fakeCmdRunner1, 'testInstance', 'testns'); $testObj2->addPlugin([$plugin3, $plugin4]); $testObj2->run(); $actualStr = file_get_contents(rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'cloud_watch_client.txt'); $exceptedStr = ''; $exceptedStr .= json_encode($this->tester->getMetricDataArray($plugin3->getMetrics(), 'testInstance', 'Test/System')) . "\n"; $this->assertEquals($exceptedStr, $actualStr, 'Sender::run cron test failed!'); }