summaryrefslogtreecommitdiff
path: root/app/httpclient_test.go
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-07-15 02:25:20 -0500
committerChristian Cleberg <[email protected]>2026-07-15 02:25:20 -0500
commitd6789522d3dd076f7c98dafa3e7d42df09252093 (patch)
tree4f27291432e367a32be581654b010ad19c5497aa /app/httpclient_test.go
parent7eb5e5e2230b6fb5b1bed6f0eaa03279aa61555b (diff)
downloadskunky-art-d6789522d3dd076f7c98dafa3e7d42df09252093.tar.gz
skunky-art-d6789522d3dd076f7c98dafa3e7d42df09252093.tar.bz2
skunky-art-d6789522d3dd076f7c98dafa3e7d42df09252093.zip
fix: document exported API, fix naming, and harden Downloadv1.3.3
The remaining golangci-lint findings. These land together because the Url -> URL rename spans util.go, parsers.go and wrapper.go, and splitting it would leave an intermediate commit that does not compile. Download() carried the most serious bug here: try() only prints an error, it does not return, so a failed request fell through to resp.Body.Close() on a nil resp and panicked. Every failure path now returns the zero Downloaded, and callers check Status. ReturnHTTPError guards against the resulting status 0, which would otherwise panic WriteHeader. Requests carry a context with a timeout (noctx), and a download-proxy now routes through ProxiedTransport so it keeps the DA throttle and timeouts. Also: - doc comments on all 48 exported symbols (revive's exported rule, with checkPrivateReceivers, since most of app is exported methods on the unexported skunkyart type), plus package docs in new doc.go files so both the embed and non-embed builds are covered. - ST1003 naming: UrlBuilder -> URLBuilder, id_search -> idSearch, cache_config -> cacheConfig, TXT_RAW -> TxtRaw, mediaUrl -> mediaURL. - explicit json tags on structs that are unmarshaled (musttag); the hyphenated keys already had tags, the rest relied on case-insensitive fallback. Behaviour is unchanged. - modernization: range-over-int, WaitGroup.Go, stale +build lines, interface{} -> any, strings.Builder over string concatenation in a loop.
Diffstat (limited to 'app/httpclient_test.go')
-rw-r--r--app/httpclient_test.go18
1 files changed, 8 insertions, 10 deletions
diff --git a/app/httpclient_test.go b/app/httpclient_test.go
index 650360e..af7dd7d 100644
--- a/app/httpclient_test.go
+++ b/app/httpclient_test.go
@@ -21,8 +21,8 @@ func (s *stubTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return httptest.NewRecorder().Result(), nil
}
-func newTestThrottle(base http.RoundTripper, gap time.Duration, max int) *daThrottle {
- return &daThrottle{base: base, sem: make(chan struct{}, max)}
+func newTestThrottle(base http.RoundTripper, gap time.Duration, maxConcurrent int) *daThrottle {
+ return &daThrottle{base: base, sem: make(chan struct{}, maxConcurrent)}
}
// DeviantArt requests must be spaced by at least daMinInterval.
@@ -32,7 +32,7 @@ func TestThrottleRateLimitsDeviantArt(t *testing.T) {
start := time.Now()
const n = 3
- for i := 0; i < n; i++ {
+ for range n {
req, _ := http.NewRequest("GET", "https://www.deviantart.com/_puppy/x", nil)
if _, err := tr.RoundTrip(req); err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -55,7 +55,7 @@ func TestThrottleSkipsOtherHosts(t *testing.T) {
tr := newTestThrottle(stub, daMinInterval, daMaxConcurrent)
start := time.Now()
- for i := 0; i < 5; i++ {
+ for range 5 {
req, _ := http.NewRequest("GET", "https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/x.jpg", nil)
if _, err := tr.RoundTrip(req); err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -96,13 +96,11 @@ func TestThrottleCapsConcurrency(t *testing.T) {
tr := newTestThrottle(counting, daMinInterval, daMaxConcurrent)
var wg sync.WaitGroup
- for i := 0; i < 6; i++ {
- wg.Add(1)
- go func() {
- defer wg.Done()
+ for range 6 {
+ wg.Go(func() {
req, _ := http.NewRequest("GET", "https://www.deviantart.com/_puppy/x", nil)
- tr.RoundTrip(req)
- }()
+ _, _ = tr.RoundTrip(req)
+ })
}
wg.Wait()