Skip to content

Commit 188ddcc

Browse files
pan93412claude
andcommitted
fix: address golangci-lint issues in pack_test.go
- Change package name to util_test for proper test isolation - Check error return value of os.Chdir in defer statements - Replace deprecated filepath.HasPrefix with strings.HasPrefix - Add proper error handling for directory restoration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 013376b commit 188ddcc

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

internal/util/pack_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
package util
1+
package util_test
22

33
import (
44
"archive/zip"
55
"bytes"
66
"os"
77
"path/filepath"
8+
"strings"
89
"testing"
10+
11+
"github.com/zeabur/cli/internal/util"
912
)
1013

1114
func TestPackZipWithZeaburIgnore(t *testing.T) {
@@ -21,7 +24,11 @@ func TestPackZipWithZeaburIgnore(t *testing.T) {
2124
if err != nil {
2225
t.Fatalf("Failed to get current dir: %v", err)
2326
}
24-
defer os.Chdir(originalDir)
27+
defer func() {
28+
if err := os.Chdir(originalDir); err != nil {
29+
t.Errorf("Failed to restore directory: %v", err)
30+
}
31+
}()
2532

2633
if err := os.Chdir(tmpDir); err != nil {
2734
t.Fatalf("Failed to change to temp dir: %v", err)
@@ -60,7 +67,7 @@ func TestPackZipWithZeaburIgnore(t *testing.T) {
6067
}
6168

6269
// Pack the zip
63-
zipBytes, err := PackZipWithoutGitIgnoreFiles()
70+
zipBytes, err := util.PackZipWithoutGitIgnoreFiles()
6471
if err != nil {
6572
t.Fatalf("PackZipWithoutGitIgnoreFiles failed: %v", err)
6673
}
@@ -101,7 +108,7 @@ func TestPackZipWithZeaburIgnore(t *testing.T) {
101108

102109
// Check that .git directory is excluded
103110
for path := range filesInZip {
104-
if filepath.HasPrefix(path, ".git/") || filepath.HasPrefix(path, ".git\\") {
111+
if strings.HasPrefix(path, ".git/") || strings.HasPrefix(path, ".git\\") {
105112
t.Errorf("File %s should be excluded (.git directory) but found in zip", path)
106113
}
107114
}
@@ -120,7 +127,11 @@ func TestPackZipWithoutZeaburIgnore(t *testing.T) {
120127
if err != nil {
121128
t.Fatalf("Failed to get current dir: %v", err)
122129
}
123-
defer os.Chdir(originalDir)
130+
defer func() {
131+
if err := os.Chdir(originalDir); err != nil {
132+
t.Errorf("Failed to restore directory: %v", err)
133+
}
134+
}()
124135

125136
if err := os.Chdir(tmpDir); err != nil {
126137
t.Fatalf("Failed to change to temp dir: %v", err)
@@ -146,7 +157,7 @@ func TestPackZipWithoutZeaburIgnore(t *testing.T) {
146157
}
147158

148159
// Pack the zip
149-
zipBytes, err := PackZipWithoutGitIgnoreFiles()
160+
zipBytes, err := util.PackZipWithoutGitIgnoreFiles()
150161
if err != nil {
151162
t.Fatalf("PackZipWithoutGitIgnoreFiles failed: %v", err)
152163
}

0 commit comments

Comments
 (0)