Skip to content

Commit 398aa22

Browse files
andy-tier1appclaude
andcommitted
Re-enable zip test with proper temp directory setup
- Removed t.Skip() and rewrote TestZipFolder to use a temporary directory - Added debug logging to trace execution in CI - Temporarily limited CI to run only the zip test for debugging 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 10c24bb commit 398aa22

File tree

2 files changed

+95
-15
lines changed

2 files changed

+95
-15
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ jobs:
118118

119119
- name: Run tests with coverage (excluding CGO-dependent packages)
120120
run: |
121-
go test -v -race -coverprofile=coverage.out -covermode=atomic $(go list ./... | grep -v 'internal/cli' | grep -v 'internal/capture/procps/linux')
122-
123-
- name: Display coverage summary
124-
run: |
125-
go tool cover -func=coverage.out | tail -20
126-
echo ""
127-
echo "=== Total Coverage ==="
128-
go tool cover -func=coverage.out | grep total
121+
# TEMP: Run only zip test for debugging
122+
go test -v -race ./internal/agent/ondemand/... -run TestZipFolder
123+
124+
# TEMP: Skipping coverage summary while debugging zip test
125+
# - name: Display coverage summary
126+
# run: |
127+
# go tool cover -func=coverage.out | tail -20
128+
# echo ""
129+
# echo "=== Total Coverage ==="
130+
# go tool cover -func=coverage.out | grep total
129131

130132

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,93 @@
11
package ondemand
22

3-
import "testing"
3+
import (
4+
"archive/zip"
5+
"os"
6+
"path/filepath"
7+
"testing"
8+
)
49

510
func TestZipFolder(t *testing.T) {
6-
// TODO: Revisit this test - currently failing in CI
7-
// Test may fail if "zip" folder doesn't exist or is not accessible in CI environment.
8-
// Needs proper test data setup or mocking of filesystem.
9-
t.Skip("Skipping until zip folder test can be properly set up")
11+
// Create a temporary directory for the test
12+
tempDir, err := os.MkdirTemp("", "ziptest")
13+
if err != nil {
14+
t.Fatalf("Failed to create temp dir: %v", err)
15+
}
16+
defer os.RemoveAll(tempDir)
17+
18+
t.Logf("DEBUG: Created temp dir: %s", tempDir)
19+
20+
// Create a test folder inside temp dir
21+
testFolder := filepath.Join(tempDir, "testfolder")
22+
err = os.Mkdir(testFolder, 0755)
23+
if err != nil {
24+
t.Fatalf("Failed to create test folder: %v", err)
25+
}
26+
t.Logf("DEBUG: Created test folder: %s", testFolder)
27+
28+
// Create some test files
29+
testFiles := []struct {
30+
name string
31+
content string
32+
}{
33+
{"file1.txt", "Hello, World!"},
34+
{"file2.txt", "Test content"},
35+
{"file3.log", "Log data here"},
36+
}
37+
38+
for _, tf := range testFiles {
39+
filePath := filepath.Join(testFolder, tf.name)
40+
err = os.WriteFile(filePath, []byte(tf.content), 0644)
41+
if err != nil {
42+
t.Fatalf("Failed to create test file %s: %v", tf.name, err)
43+
}
44+
t.Logf("DEBUG: Created test file: %s", filePath)
45+
}
46+
47+
// Change to temp dir so the zip is created there
48+
originalDir, err := os.Getwd()
49+
if err != nil {
50+
t.Fatalf("Failed to get current dir: %v", err)
51+
}
52+
defer os.Chdir(originalDir)
1053

11-
_, err := ZipFolder("zip")
54+
err = os.Chdir(tempDir)
1255
if err != nil {
13-
t.Fatal(err)
56+
t.Fatalf("Failed to change to temp dir: %v", err)
1457
}
58+
t.Logf("DEBUG: Changed to dir: %s", tempDir)
59+
60+
// Call ZipFolder with the relative path
61+
zipName, err := ZipFolder("testfolder")
62+
if err != nil {
63+
t.Fatalf("ZipFolder failed: %v", err)
64+
}
65+
t.Logf("DEBUG: Created zip file: %s", zipName)
66+
67+
// Verify the zip file was created
68+
zipPath := filepath.Join(tempDir, zipName)
69+
if _, err := os.Stat(zipPath); os.IsNotExist(err) {
70+
t.Fatalf("Zip file was not created at %s", zipPath)
71+
}
72+
t.Logf("DEBUG: Verified zip exists at: %s", zipPath)
73+
74+
// Open and verify the zip contents
75+
reader, err := zip.OpenReader(zipPath)
76+
if err != nil {
77+
t.Fatalf("Failed to open zip file: %v", err)
78+
}
79+
defer reader.Close()
80+
81+
t.Logf("DEBUG: Zip contains %d files", len(reader.File))
82+
for _, f := range reader.File {
83+
t.Logf("DEBUG: Zip entry: %s (size: %d)", f.Name, f.UncompressedSize64)
84+
}
85+
86+
// Verify all test files are in the zip
87+
if len(reader.File) != len(testFiles) {
88+
t.Errorf("Expected %d files in zip, got %d", len(testFiles), len(reader.File))
89+
}
90+
91+
// Cleanup the zip file
92+
os.Remove(zipPath)
1593
}

0 commit comments

Comments
 (0)