| 30 | } |
| 31 | |
| 32 | func TestUnzip_Success(t *testing.T) { |
| 33 | tmpDir := t.TempDir() |
| 34 | zipPath := filepath.Join(tmpDir, "test.zip") |
| 35 | destDir := filepath.Join(tmpDir, "out") |
| 36 | |
| 37 | files := map[string]string{ |
| 38 | "file1.txt": "hello", |
| 39 | "dir/file2.txt": "world", |
| 40 | "dir/sub/file3.txt": "nested", |
| 41 | } |
| 42 | createZip(t, zipPath, files) |
| 43 | |
| 44 | err := Unzip(zipPath, destDir) |
| 45 | if err != nil { |
| 46 | t.Fatalf("Unzip failed: %v", err) |
| 47 | } |
| 48 | |
| 49 | for name, content := range files { |
| 50 | fullPath := filepath.Join(destDir, name) |
| 51 | data, err := os.ReadFile(fullPath) |
| 52 | if err != nil { |
| 53 | t.Errorf("failed to read %s: %v", name, err) |
| 54 | continue |
| 55 | } |
| 56 | if string(data) != content { |
| 57 | t.Errorf("expected content %q in %s but got %q", content, name, string(data)) |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestUnzip_IllegalPath(t *testing.T) { |
| 63 | tmpDir := t.TempDir() |