Skip to content

Commit

Permalink
test unzip
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiwara committed Feb 1, 2025
1 parent b6bec17 commit 023da02
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"archive/zip"
"fmt"
"os"
"path/filepath"
"slices"
"sort"
"testing"

"time"

"github.com/fujiwara/lambroll"
Expand Down Expand Up @@ -115,3 +118,30 @@ func TestLoadNotZipArchive(t *testing.T) {
}
t.Log(err)
}

func TestUnzip(t *testing.T) {
dest := t.TempDir()
if err := lambroll.Unzip("test/src.zip", dest, false); err != nil {
t.Error("failed to Unzip", err)
}
unzipEntries := []string{}
err := filepath.WalkDir(dest, func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
rel, _ := filepath.Rel(dest, path)
unzipEntries = append(unzipEntries, rel)
return nil
})
if err != nil {
t.Error("failed to walk", err)
}
sort.Strings(unzipEntries)
expected := []string{"dir/sub.txt", "hello.txt", "world"}
if diff := cmp.Diff(unzipEntries, expected); diff != "" {
t.Errorf("unexpected unzip entries %s", diff)
}
}
1 change: 1 addition & 0 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
MarshalJSON = marshalJSON
NewFunctionFrom = newFunctionFrom
NewCallerIdentity = newCallerIdentity
Unzip = unzip
)

type VersionsOutput = versionsOutput
Expand Down

0 comments on commit 023da02

Please sign in to comment.