Skip to content

Commit e29627a

Browse files
committed
fix lint findings
1 parent 966aea8 commit e29627a

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ The metrics exposed beyond the default Prometheus metrics are:
184184
outgoing HTTP POST to upload the deployment record.
185185
* `deptracker_post_record_ok`: the number of successful deployment
186186
record uploads.
187-
* `deptracker_post_record_rate_limited`: the number of post attempts
187+
* `deptracker_post_record_rate_limited`: the number of post attempts
188188
that were rate limited.
189-
* `deptracker_post_record_no_attestation`: the number of successful
189+
* `deptracker_post_record_no_attestation`: the number of successful
190190
posts for container digest with no matching attestation for the org.
191191
* `deptracker_post_record_soft_fail`: the number of recoverable failed
192192
attempts to upload the deployment record.

pkg/deploymentrecord/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ type NoArtifactError struct {
166166
}
167167

168168
func (n *NoArtifactError) Error() string {
169-
if n.err == nil {
170-
return "no artifact found"
171-
}
172169
return fmt.Sprintf("no artifact found: %s", n.err.Error())
173170
}
174171

@@ -277,7 +274,7 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
277274
"attempt", attempt,
278275
"status_code", resp.StatusCode,
279276
)
280-
return &NoArtifactError{}
277+
return &NoArtifactError{err: fmt.Errorf("no attestation found for %s", record.Digest)}
281278
case resp.StatusCode >= 400 && resp.StatusCode < 500:
282279
if resp.Header.Get("retry-after") != "" || resp.Header.Get("x-ratelimit-remaining") == "0" {
283280
// rate limited — retry with backoff

pkg/deploymentrecord/client_test.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,15 @@ func TestPostOne(t *testing.T) {
321321
{
322322
name: "success on 200",
323323
record: testRecord(),
324-
handler: func(w http.ResponseWriter, r *http.Request) {
324+
handler: func(w http.ResponseWriter, _ *http.Request) {
325325
w.WriteHeader(http.StatusOK)
326326
},
327327
wantOk: 1,
328328
},
329329
{
330330
name: "success on 201",
331331
record: testRecord(),
332-
handler: func(w http.ResponseWriter, r *http.Request) {
332+
handler: func(w http.ResponseWriter, _ *http.Request) {
333333
w.WriteHeader(http.StatusCreated)
334334
},
335335
wantOk: 1,
@@ -338,26 +338,27 @@ func TestPostOne(t *testing.T) {
338338
name: "nil record returns error",
339339
record: nil,
340340
wantErr: true,
341-
handler: func(w http.ResponseWriter, r *http.Request) {
341+
handler: func(_ http.ResponseWriter, _ *http.Request) {
342342
t.Fatal("server should not be called with nil record")
343343
},
344344
errContain: "record cannot be nil",
345345
},
346346
{
347347
name: "404 with no artifacts found returns NoArtifactError",
348348
record: testRecord(),
349-
handler: func(w http.ResponseWriter, r *http.Request) {
349+
handler: func(w http.ResponseWriter, _ *http.Request) {
350350
w.WriteHeader(http.StatusNotFound)
351351
_, _ = w.Write([]byte(`{"message":"no artifacts found"}`))
352352
},
353353
wantErr: true,
354354
errType: &NoArtifactError{},
355+
errContain: "sha256:abc123",
355356
wantNoAttestation: 1,
356357
},
357358
{
358359
name: "404 without no artifacts found returns ClientError",
359360
record: testRecord(),
360-
handler: func(w http.ResponseWriter, r *http.Request) {
361+
handler: func(w http.ResponseWriter, _ *http.Request) {
361362
w.WriteHeader(http.StatusNotFound)
362363
_, _ = w.Write([]byte(`{"message":"not found"}`))
363364
},
@@ -368,7 +369,7 @@ func TestPostOne(t *testing.T) {
368369
{
369370
name: "400 returns ClientError",
370371
record: testRecord(),
371-
handler: func(w http.ResponseWriter, r *http.Request) {
372+
handler: func(w http.ResponseWriter, _ *http.Request) {
372373
w.WriteHeader(http.StatusBadRequest)
373374
_, _ = w.Write([]byte("bad request"))
374375
},
@@ -379,7 +380,7 @@ func TestPostOne(t *testing.T) {
379380
{
380381
name: "403 forbidden returns ClientError",
381382
record: testRecord(),
382-
handler: func(w http.ResponseWriter, r *http.Request) {
383+
handler: func(w http.ResponseWriter, _ *http.Request) {
383384
w.WriteHeader(http.StatusForbidden)
384385
_, _ = w.Write([]byte(`{"message":"forbidden"}`))
385386
},
@@ -391,7 +392,7 @@ func TestPostOne(t *testing.T) {
391392
name: "429 rate limit retries then fails",
392393
record: testRecord(),
393394
retries: 1,
394-
handler: func(w http.ResponseWriter, r *http.Request) {
395+
handler: func(w http.ResponseWriter, _ *http.Request) {
395396
w.Header().Set("Retry-After", "1")
396397
w.WriteHeader(http.StatusTooManyRequests)
397398
},
@@ -404,7 +405,7 @@ func TestPostOne(t *testing.T) {
404405
name: "403 with Retry-After header retries then fails",
405406
record: testRecord(),
406407
retries: 1,
407-
handler: func(w http.ResponseWriter, r *http.Request) {
408+
handler: func(w http.ResponseWriter, _ *http.Request) {
408409
w.Header().Set("Retry-After", "1")
409410
w.WriteHeader(http.StatusForbidden)
410411
_, _ = w.Write([]byte(`{"message":"rate limit"}`))
@@ -418,7 +419,7 @@ func TestPostOne(t *testing.T) {
418419
name: "403 with x-ratelimit-remaining 0 retries then fails",
419420
record: testRecord(),
420421
retries: 1,
421-
handler: func(w http.ResponseWriter, r *http.Request) {
422+
handler: func(w http.ResponseWriter, _ *http.Request) {
422423
w.Header().Set("X-Ratelimit-Remaining", "0")
423424
w.WriteHeader(http.StatusForbidden)
424425
},
@@ -431,7 +432,7 @@ func TestPostOne(t *testing.T) {
431432
name: "500 server error retries then fails",
432433
record: testRecord(),
433434
retries: 1,
434-
handler: func(w http.ResponseWriter, r *http.Request) {
435+
handler: func(w http.ResponseWriter, _ *http.Request) {
435436
w.WriteHeader(http.StatusInternalServerError)
436437
_, _ = w.Write([]byte("internal error"))
437438
},
@@ -446,7 +447,7 @@ func TestPostOne(t *testing.T) {
446447
retries: 2,
447448
handler: func() http.HandlerFunc {
448449
var count atomic.Int32
449-
return func(w http.ResponseWriter, r *http.Request) {
450+
return func(w http.ResponseWriter, _ *http.Request) {
450451
if count.Add(1) == 1 {
451452
w.WriteHeader(http.StatusInternalServerError)
452453
return
@@ -463,7 +464,7 @@ func TestPostOne(t *testing.T) {
463464
retries: 2,
464465
handler: func() http.HandlerFunc {
465466
var count atomic.Int32
466-
return func(w http.ResponseWriter, r *http.Request) {
467+
return func(w http.ResponseWriter, _ *http.Request) {
467468
if count.Add(1) == 1 {
468469
w.Header().Set("Retry-After", "0")
469470
w.WriteHeader(http.StatusTooManyRequests)
@@ -481,7 +482,7 @@ func TestPostOne(t *testing.T) {
481482
retries: 2,
482483
handler: func() http.HandlerFunc {
483484
var count atomic.Int32
484-
return func(w http.ResponseWriter, r *http.Request) {
485+
return func(w http.ResponseWriter, _ *http.Request) {
485486
if count.Add(1) == 1 {
486487
w.Header().Set("Retry-After", "0")
487488
w.WriteHeader(http.StatusForbidden)
@@ -535,6 +536,8 @@ func TestPostOne(t *testing.T) {
535536
if !errors.As(err, &e) {
536537
t.Errorf("expected ClientError, got %T: %v", err, err)
537538
}
539+
default:
540+
t.Fatalf("unexpected error type in test: %T", target)
538541
}
539542
}
540543
if tt.errContain != "" && !strings.Contains(err.Error(), tt.errContain) {

0 commit comments

Comments
 (0)