Fix formatting in fetcher and signature tests

This commit is contained in:
2026-01-08 03:36:00 -08:00
parent 30c5c077e5
commit 6d32b7ee23
2 changed files with 33 additions and 33 deletions

View File

@@ -13,12 +13,12 @@ import (
// Fetcher configuration constants. // Fetcher configuration constants.
const ( const (
DefaultFetchTimeout = 30 * time.Second DefaultFetchTimeout = 30 * time.Second
DefaultMaxResponseSize = 50 << 20 // 50MB DefaultMaxResponseSize = 50 << 20 // 50MB
DefaultTLSTimeout = 10 * time.Second DefaultTLSTimeout = 10 * time.Second
DefaultMaxIdleConns = 100 DefaultMaxIdleConns = 100
DefaultIdleConnTimeout = 90 * time.Second DefaultIdleConnTimeout = 90 * time.Second
DefaultMaxRedirects = 10 DefaultMaxRedirects = 10
) )
// Fetcher errors. // Fetcher errors.
@@ -148,7 +148,7 @@ func (f *HTTPFetcher) Fetch(ctx context.Context, url string) (*FetchResult, erro
// Wrap body with size limiter // Wrap body with size limiter
limitedBody := &limitedReader{ limitedBody := &limitedReader{
reader: resp.Body, reader: resp.Body,
remaining: f.config.MaxResponseSize, remaining: f.config.MaxResponseSize,
} }

View File

@@ -58,11 +58,11 @@ func TestSigner_Verify(t *testing.T) {
name: "valid signature", name: "valid signature",
setup: func() *ImageRequest { setup: func() *ImageRequest {
req := &ImageRequest{ req := &ImageRequest{
SourceHost: "cdn.example.com", SourceHost: "cdn.example.com",
SourcePath: "/photos/cat.jpg", SourcePath: "/photos/cat.jpg",
Size: Size{Width: 800, Height: 600}, Size: Size{Width: 800, Height: 600},
Format: FormatWebP, Format: FormatWebP,
Expires: time.Now().Add(1 * time.Hour), Expires: time.Now().Add(1 * time.Hour),
} }
req.Signature = signer.Sign(req) req.Signature = signer.Sign(req)
@@ -74,11 +74,11 @@ func TestSigner_Verify(t *testing.T) {
name: "expired signature", name: "expired signature",
setup: func() *ImageRequest { setup: func() *ImageRequest {
req := &ImageRequest{ req := &ImageRequest{
SourceHost: "cdn.example.com", SourceHost: "cdn.example.com",
SourcePath: "/photos/cat.jpg", SourcePath: "/photos/cat.jpg",
Size: Size{Width: 800, Height: 600}, Size: Size{Width: 800, Height: 600},
Format: FormatWebP, Format: FormatWebP,
Expires: time.Now().Add(-1 * time.Hour), // Expired Expires: time.Now().Add(-1 * time.Hour), // Expired
} }
req.Signature = signer.Sign(req) req.Signature = signer.Sign(req)
@@ -90,12 +90,12 @@ func TestSigner_Verify(t *testing.T) {
name: "invalid signature", name: "invalid signature",
setup: func() *ImageRequest { setup: func() *ImageRequest {
return &ImageRequest{ return &ImageRequest{
SourceHost: "cdn.example.com", SourceHost: "cdn.example.com",
SourcePath: "/photos/cat.jpg", SourcePath: "/photos/cat.jpg",
Size: Size{Width: 800, Height: 600}, Size: Size{Width: 800, Height: 600},
Format: FormatWebP, Format: FormatWebP,
Expires: time.Now().Add(1 * time.Hour), Expires: time.Now().Add(1 * time.Hour),
Signature: "invalid-signature", Signature: "invalid-signature",
} }
}, },
wantErr: ErrSignatureInvalid, wantErr: ErrSignatureInvalid,
@@ -118,11 +118,11 @@ func TestSigner_Verify(t *testing.T) {
name: "tampered request", name: "tampered request",
setup: func() *ImageRequest { setup: func() *ImageRequest {
req := &ImageRequest{ req := &ImageRequest{
SourceHost: "cdn.example.com", SourceHost: "cdn.example.com",
SourcePath: "/photos/cat.jpg", SourcePath: "/photos/cat.jpg",
Size: Size{Width: 800, Height: 600}, Size: Size{Width: 800, Height: 600},
Format: FormatWebP, Format: FormatWebP,
Expires: time.Now().Add(1 * time.Hour), Expires: time.Now().Add(1 * time.Hour),
} }
req.Signature = signer.Sign(req) req.Signature = signer.Sign(req)
// Tamper with the request // Tamper with the request
@@ -157,11 +157,11 @@ func TestSigner_DifferentKeys(t *testing.T) {
signer2 := NewSigner("secret-key-2") signer2 := NewSigner("secret-key-2")
req := &ImageRequest{ req := &ImageRequest{
SourceHost: "cdn.example.com", SourceHost: "cdn.example.com",
SourcePath: "/photos/cat.jpg", SourcePath: "/photos/cat.jpg",
Size: Size{Width: 800, Height: 600}, Size: Size{Width: 800, Height: 600},
Format: FormatWebP, Format: FormatWebP,
Expires: time.Now().Add(1 * time.Hour), Expires: time.Now().Add(1 * time.Hour),
} }
// Sign with key 1 // Sign with key 1