Fix missing User-Agent header in Upload API client#42
Conversation
WalkthroughThe upload API client now computes and applies a User-Agent header during initialization. The client struct adds a ChangesUser-Agent Header Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ucare/uploadapi_test.go (1)
59-77: ⚡ Quick winStrengthen User-Agent assertions to exact expected value.
These checks only validate substring presence, so malformed ordering/format could still pass. Assert the full expected header value per case.
Proposed test tightening
@@ import ( "context" "encoding/json" "errors" + "fmt" "io" "net/http" "net/http/httptest" - "strings" "sync/atomic" "testing" @@ { test: "user_agent", @@ checkReq: func(r *http.Request) error { - if !strings.Contains(r.Header.Get("User-Agent"), config.UserAgentPrefix+"/") { - return errors.New("expected User-Agent to contain UploadcareGo/") + expected := fmt.Sprintf("%s/%s/%s", config.UserAgentPrefix, config.ClientVersion, testCreds().PublicKey) + if r.Header.Get("User-Agent") != expected { + return errors.New("unexpected User-Agent value") } return nil }, }, @@ checkReq: func(r *http.Request) error { - userAgent := r.Header.Get("User-Agent") - if !strings.Contains(userAgent, config.UserAgentPrefix+"/") { - return errors.New("expected User-Agent to contain UploadcareGo/") - } - if !strings.Contains(userAgent, "MyApp/1.0") { - return errors.New("expected User-Agent to contain custom value") + expected := fmt.Sprintf("%s/%s/%s MyApp/1.0", config.UserAgentPrefix, config.ClientVersion, testCreds().PublicKey) + if r.Header.Get("User-Agent") != expected { + return errors.New("unexpected User-Agent value") } return nil }, },🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ucare/uploadapi_test.go` around lines 59 - 77, Replace the loose substring checks in the checkReq funcs with exact equality assertions for the full User-Agent header: in the "default_user_agent" case compute an explicit expectedUserAgent (e.g. config.UserAgentPrefix + "/" + "<expected-version>") and assert r.Header.Get("User-Agent") == expectedUserAgent; in the "custom_user_agent" case compute expectedUserAgent as the default value plus the custom suffix (e.g. config.UserAgentPrefix + "/" + "<expected-version>" + " MyApp/1.0") and assert equality instead of using strings.Contains; update the two checkReq closures to fail when the header does not exactly match the constructed expectedUserAgent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@ucare/uploadapi_test.go`:
- Around line 59-77: Replace the loose substring checks in the checkReq funcs
with exact equality assertions for the full User-Agent header: in the
"default_user_agent" case compute an explicit expectedUserAgent (e.g.
config.UserAgentPrefix + "/" + "<expected-version>") and assert
r.Header.Get("User-Agent") == expectedUserAgent; in the "custom_user_agent" case
compute expectedUserAgent as the default value plus the custom suffix (e.g.
config.UserAgentPrefix + "/" + "<expected-version>" + " MyApp/1.0") and assert
equality instead of using strings.Contains; update the two checkReq closures to
fail when the header does not exactly match the constructed expectedUserAgent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 66469446-0ab2-452a-97d5-9d41995b106c
📒 Files selected for processing (2)
ucare/uploadapi.goucare/uploadapi_test.go
UploadcareGo/<version>/<public key>.Config.UserAgentvalues when provided viaWithUserAgent.Summary by CodeRabbit
New Features
Tests