Skip to content

Commit 78138b9

Browse files
committed
files: use errors.Is with gzip.ErrHeader and improve test tempdir handling
1 parent 5ecd41c commit 78138b9

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

files/identification.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package files
33
import (
44
"bytes"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"io"
89
"os"
910
"path/filepath"
1011
"strings"
12+
"compress/gzip"
1113

1214
"github.com/meshery/meshkit/encoding"
1315
"github.com/meshery/meshkit/models/oci"
@@ -304,7 +306,7 @@ func ParseFileAsHelmChart(file SanitizedFile) (*chart.Chart, error) {
304306
if err != nil {
305307
// If the file extension was an uncompressed .tar and the loader failed
306308
// due to gzip/invalid header, provide a human friendly hint.
307-
if file.FileExt == ".tar" && strings.Contains(err.Error(), "gzip: invalid header") {
309+
if file.FileExt == ".tar" && errors.Is(err, gzip.ErrHeader) {
308310
return nil, ErrUncompressedTarProvided(file.FileName, err)
309311
}
310312
return nil, fmt.Errorf("failed to load Helm chart %v", err)

files/tests/sanitization_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ func TestUncompressedHelmTarError(t *testing.T) {
217217
t.Fatalf("failed to close tar writer: %v", err)
218218
}
219219

220-
tempDir, _ := os.MkdirTemp("", "temp-tests")
220+
tempDir, err := os.MkdirTemp("", "temp-tests")
221+
if err != nil {
222+
t.Fatalf("failed to create temp directory: %v", err)
223+
}
221224
defer os.RemoveAll(tempDir)
222225

223226
validExts := map[string]bool{

0 commit comments

Comments
 (0)