Fix some testing issues (#16174)

* Fix some testing issues
index doesn't exist in ModuleTestHelper
Cache issue in NetSnmpQuery (specifically affects testing)

* Apply fixes from StyleCI

---------

Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
This commit is contained in:
Tony Murray
2024-07-02 09:21:39 -05:00
committed by GitHub
parent 0cee13c831
commit 3aedfb4f3b
2 changed files with 18 additions and 5 deletions

View File

@@ -407,8 +407,21 @@ class NetSnmpQuery implements SnmpQueryInterface
private function exec(string $command, array $oids): SnmpResponse
{
// use runtime(array) cache if requested. The 'null' driver will simply return the value without caching
$driver = $this->cache ? 'array' : 'null';
$key = $this->cache ? $this->getCacheKey($command, $oids) : '';
$driver = 'null';
$key = '';
if ($this->cache) {
$driver = 'array';
$key = $this->getCacheKey($command, $oids);
if (Debug::isEnabled()) {
if (Cache::driver($driver)->has($key)) {
Log::debug("Cache hit for $command " . implode(',', $oids));
} else {
Log::debug("Cache miss for $command " . implode(',', $oids) . ', grabbing fresh data.');
}
}
}
return Cache::driver($driver)->rememberForever($key, function () use ($command, $oids) {
$measure = Measurement::start($command);
@@ -546,6 +559,6 @@ class NetSnmpQuery implements SnmpQueryInterface
$oids = implode(',', $oids);
$options = implode(',', $this->options);
return "$type|{$this->device->hostname}|$this->context|$oids|$options";
return "$type|{$this->device->hostname}|{$this->device->community}|$this->context|$oids|$options";
}
}