Skip to content

Add unit tests for utils and runner packages#4

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/add-unit-test
Draft

Add unit tests for utils and runner packages#4
Copilot wants to merge 2 commits into
mainfrom
copilot/add-unit-test

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 28, 2025

The repository had minimal test coverage (single test file with 2 functions). This adds 57 test cases across critical utility functions.

Changes

pkg/internal/utils/basic_test.go - HTTP Basic Auth handling

  • ParseBasicAuth: validates header parsing, encoding edge cases, malformed input
  • FormathBasicAuth: tests encoding with special characters, nil handling
  • Round-trip verification for encode/decode symmetry

pkg/internal/utils/network_test.go - Network error detection

  • IsNetWorkError: EOF conditions, network timeouts, error wrapping
  • IsHTTPResponseError: status code handling (429, 5xx), nil response cases
  • Mock network error types for interface validation

pkg/runner/read_count_test.go - Byte tracking reader

  • Context cancellation/timeout handling
  • Thread-safe concurrent access patterns
  • Partial reads, error propagation, large file scenarios

Coverage

  • pkg/internal/utils: 0% → 54.1%
  • pkg/runner: 0% → 2.5% (tested functions)

All tests use table-driven patterns with subtests, no external dependencies.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add unit test</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Added tests for pkg/internal/utils/basic.go (ParseBasicAuth, FormathBasicAuth)
- Added tests for pkg/internal/utils/network.go (IsNetWorkError, IsHTTPResponseError)
- Added tests for pkg/runner/read_count.go (ReadCount Read, Count methods)
- All tests passing with good coverage (54.1% for utils, 2.5% for runner)
- Tests include edge cases, error handling, and concurrent access scenarios

Co-authored-by: wzshiming <6565744+wzshiming@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit test for existing functionality Add unit tests for utils and runner packages Oct 28, 2025
Copilot AI requested a review from wzshiming October 28, 2025 09:11
@wzshiming wzshiming force-pushed the main branch 2 times, most recently from 8df29d1 to 1d34e4f Compare November 7, 2025 06:41
@wzshiming wzshiming force-pushed the main branch 3 times, most recently from dbb43f2 to 7fb2eb9 Compare November 18, 2025 11:28
@wzshiming wzshiming force-pushed the main branch 3 times, most recently from 890c265 to 94c6dc6 Compare November 21, 2025 11:33
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.

Add unit test

2 participants