add a flag for adding app data to tests generated via scripts/json-app-tool.php (#15080)

* add a means to easily add in the app data section for when generating the test data

* style fix

* minor fix for where the data should be
This commit is contained in:
Zane C. Bowers-Hadley
2023-07-21 11:55:48 -05:00
committed by GitHub
parent 64c4650801
commit e9668550af

View File

@@ -34,7 +34,7 @@ function string_to_oid($string)
}//end string_to_oid()
// Options!
$short_opts = 'S:sktmlhj:a:';
$short_opts = 'S:sktmlhj:a:d:';
$options = getopt($short_opts);
// print the help
@@ -48,6 +48,7 @@ if (isset($options['h'])) {
-k If m is specified, just print the keys in tested order.
-a The application name for use with -s and -t.
-S SNMP extend name. Defaults to the same as -a.
-d JSON file to use for app data.
-h Show this help text.
-j must always be specified.
@@ -197,6 +198,20 @@ if (isset($options['t'])) {
'app_type' => $options['a'],
];
}
// if d is specified, try to read it in and add it
if (isset($options['d'])) {
$raw_app_data = file_get_contents($options['d']);
if ($raw_json === false) {
exit(2);
}
$app_data = json_decode(stripslashes($raw_app_data), true);
if (json_last_error() !== JSON_ERROR_NONE) {
echo "Parsing '" . $options['d'] . "' failed. Running jsonlint...\n\n";
system('jsonlint ' . escapeshellarg($options['j']));
exit(3);
}
$test_data['applications']['poller']['applications']['0']['data'] = json_encode($app_data);
}
echo json_encode($test_data, JSON_PRETTY_PRINT) . "\n";
exit(0);
}