test(package): fix errorlint + exact path match in lock test

- Replace `err == io.EOF` with `errors.Is(err, io.EOF)` (errorlint).
- Match Chart.lock by full tar path ("chart-with-lock/Chart.lock")
  instead of path.Base to avoid false positives from subchart lock files.
- Break out of the loop after finding the entry (early exit).

Signed-off-by: Ilya Kiselev <kis-ilya-a@yandex.ru>
pull/32485/head
Ilya Kiselev 1 month ago
parent 3c3be926aa
commit e923167513

@ -19,6 +19,7 @@ package action
import ( import (
"archive/tar" "archive/tar"
"compress/gzip" "compress/gzip"
"errors"
"io" "io"
"os" "os"
"path" "path"
@ -180,15 +181,16 @@ func TestRunWithSourceDateEpochStampsLockGenerated(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer gr.Close() defer gr.Close()
const wantPath = "chart-with-lock/Chart.lock"
found := false found := false
tr := tar.NewReader(gr) tr := tar.NewReader(gr)
for { for {
hdr, err := tr.Next() hdr, err := tr.Next()
if err == io.EOF { if errors.Is(err, io.EOF) {
break break
} }
require.NoError(t, err) require.NoError(t, err)
if path.Base(hdr.Name) != "Chart.lock" { if hdr.Name != wantPath {
continue continue
} }
found = true found = true
@ -200,6 +202,7 @@ func TestRunWithSourceDateEpochStampsLockGenerated(t *testing.T) {
wantGenerated := epoch.Format(time.RFC3339) wantGenerated := epoch.Format(time.RFC3339)
require.Contains(t, string(raw), wantGenerated, require.Contains(t, string(raw), wantGenerated,
"Chart.lock generated: field should contain normalized UTC timestamp") "Chart.lock generated: field should contain normalized UTC timestamp")
break
} }
require.True(t, found, "expected archive to contain a Chart.lock entry") require.True(t, found, "expected archive to contain %q entry", wantPath)
} }

Loading…
Cancel
Save