Repository navigation
Respect Graph Template Test Data Source in graph automation #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c87b644
Honor Graph Template Test Data Source in graph automation
185ed46
test: do not clobber shared config in graph gate tests
c6c1ff3
test: credit real poller_graphs.php coverage for the Test Data Source…
94b3578
Load lib/snmp.php so the Test Data Source gate can probe SNMP data so…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?php | ||
| /* | ||
| +-------------------------------------------------------------------------+ | ||
| | Copyright (C) 2004-2026 The Cacti Group | | ||
| | | | ||
| | This program is free software; you can redistribute it and/or | | ||
| | modify it under the terms of the GNU General Public License | | ||
| | as published by the Free Software Foundation; either version 2 | | ||
| | of the License, or (at your option) any later version. | | ||
| | | | ||
| | This program is distributed in the hope that it will be useful, | | ||
| | but WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | ||
| | GNU General Public License for more details. | | ||
| +-------------------------------------------------------------------------+ | ||
| | Cacti: The Complete RRDtool-based Graphing Solution | | ||
| +-------------------------------------------------------------------------+ | ||
| | This code is designed, written, and maintained by the Cacti Group. See | | ||
| | about.php and/or the AUTHORS file for specific developer information. | | ||
| +-------------------------------------------------------------------------+ | ||
| | http://www.cacti.net/ | | ||
| +-------------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
| /* | ||
| * Unit coverage for the Graph Template 'Test Data Source' gate in the graph | ||
| * automation (poller_graphs.php). | ||
| * | ||
| * poller_graphs.php is a CLI entry point, so it is loaded with | ||
| * MIKROTIK_POLLER_GRAPHS_NO_MAIN defined: the file returns before its poller | ||
| * body runs and only its function definitions remain. Requiring the real file | ||
| * (rather than isolating a copy) means coverage is attributed to | ||
| * poller_graphs.php itself. | ||
| * | ||
| * The gate mirrors Cacti's own create_save_graph(): when a Graph Template has | ||
| * 'Test Data Source' enabled and the data source returns no valid data for a | ||
| * device, the graph must not be created. | ||
| */ | ||
|
|
||
| if (!function_exists('test_data_sources')) { | ||
| function test_data_sources($graph_template_id, $host_id, $snmp_query_id = 0, $snmp_index = '', $values = array()) { | ||
| $GLOBALS['__mt_tds_calls'][] = array($graph_template_id, $host_id, $snmp_query_id, $snmp_index); | ||
|
|
||
| return $GLOBALS['__mt_tds_return']; | ||
| } | ||
| } | ||
|
|
||
| if (!defined('MIKROTIK_POLLER_GRAPHS_NO_MAIN')) { | ||
| define('MIKROTIK_POLLER_GRAPHS_NO_MAIN', true); | ||
| } | ||
|
|
||
| ob_start(); | ||
| require_once dirname(__DIR__, 2) . '/poller_graphs.php'; | ||
| ob_get_clean(); | ||
|
|
||
| beforeEach(function () { | ||
| mikrotik_test_reset_db_mocks(); | ||
|
|
||
| // poller_graphs.php's debug() prints only when the global $debug is set. | ||
| $GLOBALS['debug'] = true; | ||
| $GLOBALS['__mt_tds_calls'] = array(); | ||
| $GLOBALS['__mt_tds_return'] = true; | ||
| }); | ||
|
|
||
| describe('mikrotik_gt_graph() Test Data Source gate', function () { | ||
| it('skips the graph when the data source test fails', function () { | ||
| $GLOBALS['__mt_tds_return'] = false; | ||
|
|
||
| ob_start(); | ||
| mikrotik_gt_graph(9, 11); | ||
| $out = ob_get_clean(); | ||
|
|
||
| expect($GLOBALS['__mt_tds_calls'])->toBe(array(array(11, 9, 0, ''))); | ||
| expect($out)->toContain('Skipping Graph Template'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('mikrotik_dq_graphs() Test Data Source gate', function () { | ||
| it('skips the data query graph when the data source test fails', function () { | ||
| mikrotik_test_mock_db('db_fetch_assoc_prepared', 'host_snmp_cache', array( | ||
| array('field_value' => 'eth0', 'snmp_index' => '7'), | ||
| )); | ||
|
|
||
| $GLOBALS['__mt_tds_return'] = false; | ||
|
|
||
| ob_start(); | ||
| mikrotik_dq_graphs(9, 3, 11, 5, 'ifName'); | ||
| $out = ob_get_clean(); | ||
|
|
||
| expect($GLOBALS['__mt_tds_calls'])->toBe(array(array(11, 9, 3, '7'))); | ||
| expect($out)->toContain('Skipping Data Query Graph'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.