Skip to content

Commit

Permalink
Issue #366: Recognize '2c' as a valid SNMP version option
Browse files Browse the repository at this point in the history
* Updated SnmpConfiguration to accept '2c' as a valid SNMP version.
  • Loading branch information
NassimBtk committed Aug 9, 2024
1 parent c5cf9d2 commit 26200b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ public static SnmpVersion interpretValueOf(@NonNull final String version) {
return V1;
}

if ("2".equals(lowerCaseVersion) || "v2".equals(lowerCaseVersion) || "v2c".equals(lowerCaseVersion)) {
if (
"2".equals(lowerCaseVersion) ||
"v2".equals(lowerCaseVersion) ||
"v2c".equals(lowerCaseVersion) ||
"2c".equals(lowerCaseVersion)
) {
return V2C;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sentrysoftware.metricshub.extension.snmp;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -99,4 +100,14 @@ void testValidateConfiguration() {
assertThrows(InvalidConfigurationException.class, () -> snmpConfig.validateConfiguration(resourceKey));
}
}

@Test
void testSnmpVersionInterpretValueOf() {
assertEquals(SnmpVersion.V1, SnmpVersion.interpretValueOf("1"));
assertEquals(SnmpVersion.V1, SnmpVersion.interpretValueOf("v1"));
assertEquals(SnmpVersion.V2C, SnmpVersion.interpretValueOf("2"));
assertEquals(SnmpVersion.V2C, SnmpVersion.interpretValueOf("v2"));
assertEquals(SnmpVersion.V2C, SnmpVersion.interpretValueOf("v2c"));
assertEquals(SnmpVersion.V2C, SnmpVersion.interpretValueOf("2c"));
}
}

0 comments on commit 26200b0

Please sign in to comment.