Skip to main content

Testing DNS-MNS

DNS-MNS includes a comprehensive test suite that covers both the Go binary and the Bash script. This guide explains how to run the tests and what they cover.

Test Structure

Running Tests

Run all tests without network requirements:
This runs the short test suite which completes in seconds.

Full Test Suite

Run all tests including network tests:
Network tests require internet connectivity and may take longer to complete.

Go Tests

Unit Tests

Each internal package has comprehensive unit tests:

Test Coverage

Generate a coverage report:
This creates coverage.html which you can open in your browser to see detailed coverage information.

Integration Tests

Integration tests verify the complete workflow:
These tests:
  • Load the embedded DNS list
  • Test ping functionality
  • Test DNS resolution
  • Verify platform detection
  • Build the binary
  • Test cross-platform compilation

Race Detection

Run tests with the race detector:

Bash Tests

The Bash script is tested using Bats (Bash Automated Testing System).

Install Bats

Run Bash Tests

Test Categories

What the Tests Cover

DNS List Tests

  • ✅ File exists and is readable
  • ✅ Contains all expected categories
  • ✅ All entries have valid format (NAME|IP|IP|LOCATION)
  • ✅ All IPs are valid IPv4 addresses
  • ✅ No malformed entries
  • ✅ Categories are properly defined

Go Package Tests

internal/dnslist

  • DNS list parsing from string and embedded file
  • Category filtering
  • Entry validation

internal/ping

  • Platform-specific ping output parsing
  • Average time calculation
  • Timeout handling

internal/dnstest

  • DNS resolution timing
  • Timeout handling
  • Error cases

internal/doh

  • DoH/DoT provider testing
  • Result structure validation
  • Provider list validation

internal/dnscrypt

  • DNSCrypt provider testing
  • Proxy functionality
  • Result structure validation

internal/ui

  • Color formatting
  • Progress bar rendering
  • Message formatting

internal/setter

  • Platform detection
  • Admin privilege checking
  • OS-specific code paths

Integration Tests

  • ✅ Binary can be built for all platforms
  • ✅ Embedded DNS list loads correctly
  • ✅ Complete workflow from loading to testing
  • ✅ Cross-platform compatibility

Local Testing

All testing is done locally using the Makefile and Go test commands. There is no CI/CD pipeline — run tests on your machine before committing:

Writing New Tests

Go Tests

Follow the existing patterns in *_test.go files:

Bash Tests

Test Best Practices

  1. Use table-driven tests for testing multiple inputs
  2. Skip network tests when running in short mode (if testing.Short())
  3. Skip admin tests when not running as root
  4. Use temporary directories for file operations
  5. Clean up after tests using t.TempDir() or teardown()

Troubleshooting

Tests fail with “permission denied”

Some tests require root/admin privileges. These are automatically skipped when not available.

Network tests timeout

Network tests may fail in restricted environments. Use make test (short mode) to skip them.

Bats tests not found

Make sure Bats is installed and in your PATH:
If not installed, see the Bats installation guide.

Makefile Commands