|
|
0a978746e1
|
Fix all Credo issues
Resolves 26 Credo warnings/issues:
Code Readability (2 issues):
- Break long line in mac_address.ex (line 316 > 120 chars)
- Break long @spec in agents.ex (line 332 > 120 chars)
Refactoring Opportunities (2 issues):
- Reduce cyclomatic complexity in device_live/form.ex
- Extract helper functions to simplify SNMPv3 credential resolution
- Split logic into smaller, focused functions
- Reduce nesting depth in snmp_oid.ex
- Extract nested logic into separate helper functions
Warnings (22 issues):
- Fix comparison warning in validator.ex
- Split validate_sensor_value/1 into separate clauses for int/float
- Add credo directive for valid NaN check (value != value)
- Replace 21 expensive length/1 checks with Enum.empty?/1
- Change assertions from `assert length(list) >= 1` to `refute Enum.empty?(list)`
- Change assertions from `assert length(list) > 0` to `refute Enum.empty?(list)`
- Affected files: device_poller_worker_test.exs, mib_test.exs,
snmp_tokenizer_test.exs, parser_test.exs, error_test.exs, compiler_test.exs
All tests passing (5578 tests, 0 failures).
Credo now reports: "found no issues"
|
2026-02-06 10:31:09 -06:00 |
|
|
|
07977bc16f
|
test: add comprehensive tests for MIB.SnmpTokenizer
Added complete test coverage for MIB.SnmpTokenizer module (32.93% -> target higher):
**Tokenization Tests:**
- Empty input handling
- Simple MIB header (DEFINITIONS, BEGIN, END)
- Reserved word recognition (30+ SMI keywords tested)
- Identifier tokenization (lowercase atoms, uppercase variables)
- Number tokenization (integers, negative numbers, leading zeros, large numbers)
- String tokenization with quotes
- Special characters (::=, {}, (), commas, semicolons, dots)
- OID notation
- Complete OBJECT-TYPE definitions
- Access modifiers (read-only, read-write, not-accessible, read-create)
- SMI types (INTEGER, OCTET STRING, Counter32, Gauge32, TimeTicks, IpAddress)
- Hyphenated keywords (OBJECT-TYPE, MAX-ACCESS, MODULE-IDENTITY, etc.)
**Format and Syntax:**
- Whitespace handling (spaces, tabs, newlines)
- Comment handling (-- comments)
- Multiline input
- Line number tracking
- Token order preservation
- Complex MIB structures (IMPORTS, MODULE-IDENTITY, etc.)
- SIZE constraints
- SEQUENCE OF notation
**Error Handling:**
- format_error/1 for illegal characters
- Unterminated string errors
- Unterminated quote errors
- Unknown error formatting
**Edge Cases:**
- Very long identifiers (up to 200 chars)
- Many tokens (100+ identifiers)
- Deeply nested braces
- Mixed case keywords (case-sensitive)
- Empty strings
- Consecutive operators
- Tabs and mixed whitespace
- Numbers with leading zeros
- Very large numbers
**Reserved Word Coverage:**
- All common SMI/SMIv2 reserved words tested
- Distinction between reserved words and similar identifiers
- Case-sensitive recognition
40 new tests added
Test count: 1,264 -> 1,304 (all passing)
|
2026-02-06 08:45:23 -06:00 |
|