-
Notifications
You must be signed in to change notification settings - Fork 594
test(providers): fix azure.TestUserAgent
#4780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(providers): fix azure.TestUserAgent
#4780
Conversation
Test without a proxy environment variable Authored by: @andrason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the azure.TestUserAgent test by changing its approach from using a proxy environment variable to directly testing the User-Agent header with a mock HTTP server.
- Moves the test from
azure_storage_test.goto a new fileazure_ua_test.go - Replaces proxy-based testing with direct HTTP server mocking
- Changes from testing client creation failure to testing actual blob operations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| repo/blob/azure/azure_ua_test.go | New test file containing the refactored User-Agent test using direct HTTP mocking |
| repo/blob/azure/azure_storage_test.go | Removes the old TestUserAgent function and unused imports |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| ) | ||
|
|
||
| func TestUserAgent(t *testing.T) { | ||
| ctx := t.Context() |
Copilot
AI
Aug 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using testlogging.Context(t) instead of t.Context() to ensure proper test logging context, which appears to be the pattern used in the codebase based on the removed test.
| ctx := t.Context() | |
| "github.com/kopia/kopia/internal/testlogging" | |
| ) | |
| func TestUserAgent(t *testing.T) { | |
| ctx := testlogging.Context(t) |
|
|
||
| handler := func(w http.ResponseWriter, r *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| _, _ = w.Write([]byte("test")) |
Copilot
AI
Aug 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The explicit blank identifier assignment _, _ = w.Write(...) is unnecessary. In test code, you can simply use w.Write([]byte("test")) without the assignment.
| _, _ = w.Write([]byte("test")) | |
| w.Write([]byte("test")) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4780 +/- ##
==========================================
+ Coverage 75.86% 76.39% +0.52%
==========================================
Files 470 530 +60
Lines 37301 40443 +3142
==========================================
+ Hits 28299 30897 +2598
- Misses 7071 7503 +432
- Partials 1931 2043 +112 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Leverage `require.Eventually` to prevent indefinite test hangs / timeouts, removes blocking receive op on a channel. Additional cleanups: - rename test file - remove unused const - consistently use `testloggin.Context(t)` - consistently leverage assertions from the `testify` package Refs: - #4780 - #4777
Test without a proxy environment variable
Authored by: @andrason