Skip to content

Add comprehensive unit tests for lib package#293

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/add-unit-tests-lib-package-again
Draft

Add comprehensive unit tests for lib package#293
Copilot wants to merge 3 commits intomasterfrom
copilot/add-unit-tests-lib-package-again

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 27, 2026

Adds unit tests for the lib package targeting high coverage without third-party test dependencies.

Test Coverage

  • 95.5% statement coverage achieved
  • Remaining ~4.5% is defensive error handling for edge cases impossible to trigger via public API (e.g., IPSet() failures, addresses neither IPv4 nor IPv6)

Test Files Added

  • common_test.go - HTTP functions, WantedListExtended JSON unmarshalling
  • config_test.go - Config creator registration, inputConvConfig/outputConvConfig unmarshalling
  • container_test.go - Container interface operations (Add, Remove, Lookup, GetEntry)
  • entry_test.go - Entry type with all processPrefix input types (net.IP, netip.Addr, netip.Prefix, string, pointers)
  • converter_test.go - Input/output converter registration
  • instance_test.go - Instance lifecycle, config loading (local/remote), Run execution
  • error_test.go - Error constant validation
  • lib_test.go - Constants, types, ActionsRegistry

Approach

Uses only stdlib testing and net/http/httptest. Mock converters implement InputConverter/OutputConverter interfaces for testing config and instance behavior.

// Example: testing Entry.processPrefix with various input types
func TestEntry_AddPrefix_NetipPrefix(t *testing.T) {
    e := NewEntry("test")
    prefix := netip.MustParsePrefix("192.168.0.0/16")
    if err := e.AddPrefix(prefix); err != nil {
        t.Fatalf("AddPrefix failed: %v", err)
    }
    if !e.hasIPv4Builder() {
        t.Error("expected IPv4 builder")
    }
}

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.invalid.invalid
    • Triggering command: /tmp/go-build193353414/b001/lib.test /tmp/go-build193353414/b001/lib.test -test.testlogfile=/tmp/go-build193353414/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true _.a (dns block)
    • Triggering command: /tmp/go-build4083291709/b001/lib.test /tmp/go-build4083291709/b001/lib.test -test.testlogfile=/tmp/go-build4083291709/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true _.a d/v2/chacha8.go x64/pkg/tool/linux_amd64/compile-lang=go1.24 (dns block)
    • Triggering command: /tmp/go-build1510732126/b001/lib.test /tmp/go-build1510732126/b001/lib.test -test.paniconexit0 -test.gocoverdir=/tmp/go-build1510732126/b001/gocoverdir -test.timeout=10m0s -test.coverprofile=/tmp/go-build1510732126/b001/_cover_.out jX_qTew6D (dns block)

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

Original prompt

Please write comprehensive unit tests for lib package and make sure the coverage rate is 100% if possible. Try not to use third-party Golang dependencies if possible.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 27, 2026 00:34
Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Copilot AI changed the title [WIP] Add comprehensive unit tests for lib package Add comprehensive unit tests for lib package Jan 27, 2026
Copilot AI requested a review from Loyalsoldier January 27, 2026 00:40
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