Skip to content

Commit af020c5

Browse files
committed
Review feedback
1 parent af26ee8 commit af020c5

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

internal/framework/fetch/errors.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package fetch
2+
3+
import "fmt"
4+
5+
// ChecksumMismatchError represents an error when the calculated checksum doesn't match the expected checksum.
6+
// This type of error should not trigger retries as it indicates data corruption or tampering.
7+
type ChecksumMismatchError struct {
8+
Expected string
9+
Actual string
10+
}
11+
12+
func (e *ChecksumMismatchError) Error() string {
13+
return fmt.Sprintf("checksum mismatch: expected %s, got %s", e.Expected, e.Actual)
14+
}
15+
16+
// HTTPStatusError represents an HTTP status code error for retry logic.
17+
type HTTPStatusError struct {
18+
StatusCode int
19+
}
20+
21+
func (e *HTTPStatusError) Error() string {
22+
return fmt.Sprintf("unexpected status code: %d", e.StatusCode)
23+
}

internal/framework/fetch/fetch.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,6 @@ const (
3333
checksumFileSuffix = ".sha256"
3434
)
3535

36-
// ChecksumMismatchError represents an error when the calculated checksum doesn't match the expected checksum.
37-
// This type of error should not trigger retries as it indicates data corruption or tampering.
38-
type ChecksumMismatchError struct {
39-
Expected string
40-
Actual string
41-
}
42-
43-
func (e *ChecksumMismatchError) Error() string {
44-
return fmt.Sprintf("checksum mismatch: expected %s, got %s", e.Expected, e.Actual)
45-
}
46-
47-
// HTTPStatusError represents an HTTP status code error for retry logic.
48-
type HTTPStatusError struct {
49-
StatusCode int
50-
}
51-
52-
func (e *HTTPStatusError) Error() string {
53-
return fmt.Sprintf("unexpected status code: %d", e.StatusCode)
54-
}
55-
5636
// RetryBackoffType defines supported backoff strategies.
5737
type RetryBackoffType string
5838

@@ -197,16 +177,7 @@ func (f *DefaultFetcher) GetRemoteFile(targetURL string) ([]byte, error) {
197177
return nil, fmt.Errorf("failed to fetch HTTP file after retries: %w", err)
198178
}
199179

200-
if result != nil {
201-
return result, nil
202-
}
203-
204-
// This case should ideally not be reached, but as a fallback, return the last known error.
205-
if lastErr != nil {
206-
return nil, lastErr
207-
}
208-
209-
return nil, fmt.Errorf("failed to fetch HTTP file %s: unknown error", targetURL)
180+
return result, nil
210181
}
211182

212183
// getFileContent fetches content via HTTP(S).

internal/framework/fetch/fetch_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
)
1616

1717
func TestGetRemoteFile(t *testing.T) {
18+
t.Parallel()
19+
1820
fileContent := "test file content"
1921
hasher := sha256.New()
2022
hasher.Write([]byte(fileContent))
@@ -226,6 +228,7 @@ func TestGetRemoteFile(t *testing.T) {
226228

227229
for _, tc := range tests {
228230
t.Run(tc.name, func(t *testing.T) {
231+
t.Parallel()
229232
g := NewWithT(t)
230233

231234
var serverURL string
@@ -248,6 +251,7 @@ func TestGetRemoteFile(t *testing.T) {
248251
}
249252

250253
func TestErrorTypes(t *testing.T) {
254+
t.Parallel()
251255
tests := []struct {
252256
err error
253257
unwraps error
@@ -274,6 +278,7 @@ func TestErrorTypes(t *testing.T) {
274278
for _, tc := range tests {
275279
t.Run(tc.name, func(t *testing.T) {
276280
g := NewWithT(t)
281+
t.Parallel()
277282
g.Expect(tc.err.Error()).To(Equal(tc.expected))
278283

279284
if tc.unwraps != nil {

0 commit comments

Comments
 (0)