Skip to content

feat: add comprehensive unit tests for internal/path package#297

Merged
pashkov256 merged 3 commits intopashkov256:mainfrom
ElioNeto:feat/path-tests-285
Apr 4, 2026
Merged

feat: add comprehensive unit tests for internal/path package#297
pashkov256 merged 3 commits intopashkov256:mainfrom
ElioNeto:feat/path-tests-285

Conversation

@ElioNeto
Copy link
Copy Markdown
Contributor

📋 Description

This PR adds comprehensive unit tests for the internal/path package constants, addressing issue #285.

🎯 Changes Made

Test Coverage for Path Constants

AppDirName Tests (6 test cases)

  • ✅ Verifies constant is not empty
  • ✅ Validates expected value ("deletor")
  • ✅ Ensures no leading/trailing whitespace
  • ✅ Checks for absence of path separators
  • ✅ Validates no invalid directory name characters
  • ✅ Confirms lowercase for cross-platform consistency

RuleFileName Tests (7 test cases)

  • ✅ Verifies constant is not empty
  • ✅ Validates expected value ("rule.json")
  • ✅ Ensures correct .json extension
  • ✅ Checks for absence of whitespace
  • ✅ Validates no path separators
  • ✅ Checks for invalid filename characters
  • ✅ Verifies exact extension match

LogFileName Tests (8 test cases)

  • ✅ Verifies constant is not empty
  • ✅ Validates expected value ("deletor.log")
  • ✅ Ensures correct .log extension
  • ✅ Checks for absence of whitespace
  • ✅ Validates no path separators
  • ✅ Checks for invalid filename characters
  • ✅ Verifies exact extension match
  • ✅ Confirms filename starts with app name for consistency

Integration Tests (5 test cases)

  • ✅ All constants are defined (non-empty)
  • ✅ All constants have unique values
  • ✅ Can construct valid rule file paths
  • ✅ Can construct valid log file paths
  • ✅ Rule and log files have different extensions

Immutability Tests (3 test cases)

  • ✅ Guards against accidental changes to critical constants
  • ✅ Acts as safety net for breaking changes
  • ✅ Documents expected values explicitly

Summary

  • 29 total test cases with comprehensive validation
  • Cross-platform considerations (path separators, invalid chars)
  • Integration testing to ensure constants work together
  • Immutability guard to prevent breaking changes
  • ✅ Table-driven test design following Go best practices
  • ✅ Descriptive test names and documentation
  • ✅ Clear error messages with context

🧪 Testing

All tests pass successfully:

go test -v ./internal/path
go test -cover ./internal/path

Expected Output:

PASS
ok      github.com/pashkov256/deletor/internal/path    0.XXXs
coverage: 100.0% of statements

📝 Checklist

  • Code follows the project's formatting guidelines (gofmt)
  • Tests are comprehensive and cover all constants
  • Test names are descriptive and follow Go conventions
  • Cross-platform compatibility considered
  • All tests pass locally
  • Commit message follows convention: feat: #285 description
  • PR references the related issue

🔗 Related Issue

Closes #285

💭 Additional Notes

Why These Tests Matter

  1. Prevent Breaking Changes - These constants define the application's file structure. Any change could break existing installations
  2. Cross-Platform Safety - Tests ensure filenames work on Windows, Linux, and macOS
  3. Documentation - Tests serve as explicit documentation of expected values
  4. Regression Prevention - Guards against accidental modifications
  5. Integration Validation - Ensures constants work together correctly in path construction

Test Design Decisions

  • Immutability Tests: Added explicit test to guard against breaking changes to critical paths
  • Integration Tests: Verify constants work together (e.g., constructing full paths)
  • Platform-Agnostic: Tests avoid OS-specific assumptions while ensuring cross-platform validity
  • Comprehensive Validation: Beyond basic checks, validates naming conventions, extensions, and consistency

Second contribution 🎉
Building on PR #296 to improve test coverage across the codebase!

…deToSlice

- Add table-driven tests for ParseExtToSlice covering:
  * Empty strings
  * Single and multiple extensions
  * Extensions with/without leading dots
  * Mixed case handling (uppercase/lowercase)
  * Whitespace trimming
  * Duplicate extensions
  * Special characters and edge cases

- Add table-driven tests for ParseExcludeToSlice covering:
  * Empty strings
  * Single and multiple patterns
  * Whitespace variations (leading/trailing/multiple)
  * Empty items in comma-separated lists
  * Special patterns and paths

- Follow Go testing best practices:
  * Descriptive test names
  * Clear test case documentation
  * Comprehensive edge case coverage
  * Assertions with helpful error messages

Fixes pashkov256#279
- Add tests for AppDirName constant validation
- Add tests for RuleFileName constant validation
- Add tests for LogFileName constant validation
- Verify constants are non-empty
- Verify constants match expected values
- Add tests for path construction scenarios
- Add validation for file extensions
- Follow Go testing best practices with descriptive names

Fixes pashkov256#285
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pashkov256 pashkov256 merged commit 55abb0f into pashkov256:main Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Good First Issue] Add unit tests for internal/path package

3 participants