Skip to content

Add comprehensive unit tests for lib package with 92.6% coverage#304

Draft
Claude wants to merge 2 commits intomasterfrom
claude/write-unit-tests-lib-package
Draft

Add comprehensive unit tests for lib package with 92.6% coverage#304
Claude wants to merge 2 commits intomasterfrom
claude/write-unit-tests-lib-package

Conversation

@Claude
Copy link
Copy Markdown

@Claude Claude AI commented Mar 6, 2026

Adds comprehensive unit tests for the lib package achieving 92.6% code coverage using only Go standard library packages.

Test Coverage

  • 139 test functions across 10 new test files
  • 92.6% statement coverage across all lib files
  • 100% coverage for: converter.go, instance.go, lib.go, error.go
  • 91-95% coverage for: common.go, config.go, container.go, entry.go

Files Added

  • error_test.go - Error type validation and distinctness
  • lib_test.go - Constants, types, helper functions
  • common_test.go - HTTP utilities, GetIgnoreIPType, WantedListExtended unmarshaling
  • entry_test.go - IP prefix operations, marshaling (70+ test cases)
  • container_test.go - Container operations, Add/Remove/Lookup with various options (60+ test cases)
  • converter_test.go - Converter registration and listing
  • config_test.go - Config creators and JSON unmarshaling
  • instance_test.go - Instance lifecycle, pipeline operations
  • coverage_test.go + coverage2_test.go - Edge cases and error paths

Key Test Scenarios

  • IPv4/IPv6 prefix handling including IPv4-mapped IPv6 addresses
  • Comment line processing in prefix data (#, //, /*)
  • Container operations with IgnoreIPv4/IgnoreIPv6 options
  • Entry removal with CaseRemovePrefix and CaseRemoveEntry
  • Config parsing with JSON comments and trailing commas (hujson format)
  • HTTP fetching for both local files and remote URLs
  • Marshal operations (Prefix, IPRange, Text) with filtering options
  • Lookup operations with and without search lists
  • All 11 error types and error paths

Example Test Coverage

// Tests valid IPv4/IPv6 CIDRs, invalid formats, and comment handling
func TestEntry_AddPrefix_String(t *testing.T) {
    tests := []struct {
        name    string
        prefix  string
        wantErr bool
        errType error
    }{
        {"valid IPv4 CIDR", "192.168.1.0/24", false, nil},
        {"valid IPv6 CIDR", "2001:db8::/32", false, nil},
        {"IP with comment", "192.168.1.0/24 # comment", false, nil},
        {"invalid CIDR", "192.168.1.0/33", true, ErrInvalidCIDR},
    }
    // ... test implementation
}

All tests use only Go standard library - no third-party testing frameworks or dependencies.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid-url-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build224442873/b001/lib.test /tmp/go-build224442873/b001/lib.test -test.testlogfile=/tmp/go-build224442873/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 122539/b124/_pkg_.a cfg de/node/bin/git /tmp/ccuxnvzZ.s GOAMD64_v1 l/linux_amd64/co--abbrev-ref ctor ter-�� pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/src/net--gdwarf-5 JoXp/88rT0vpzG1WI2T1jJoXp pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/pkg/tool/linux_amd64/vet --gdwarf-5 --64 l/linux_amd64/compile tf "%s%s", sep, $0; sep=RS } (dns block)
    • Triggering command: /tmp/go-build992090071/b001/lib.test /tmp/go-build992090071/b001/lib.test -test.testlogfile=/tmp/go-build992090071/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true celain --ignore-submodules | head -n 10 t uname -c -I /tmp/go-build368--abbrev-ref /home/REDACTED/go/HEAD -o /tmp/go-build368122539/b168/_pkg_.a -trimpath de/node/bin/git -p vendor/golang.or-d l/linux_amd64/vet /home/REDACTED/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linHEAD (dns block)
    • Triggering command: /tmp/go-build882738504/b001/lib.test /tmp/go-build882738504/b001/lib.test -test.testlogfile=/tmp/go-build882738504/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -uns�� #versions/iojs/#; s#^/home/REDACTED/.nvm/##; \#^[^v]# d; \#^vedirname /tmp/go-build368122539/b002/vet.cfg 0.1-go1.25.0.linux-amd64/bin/go /tmp/go-build368base64 -dumpbase l/linux_amd64/vet git rev-�� --abbrev-ref HEAD /usr/local/bin/git /g git 0.1-go1.25.0.lin--64 git (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Add comprehensive unit tests for lib package Add comprehensive unit tests for lib package with 92.6% coverage Mar 6, 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.

2 participants