Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2brain committed Nov 22, 2016
1 parent d63920e commit 0101eee
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
Binary file modified testdata/test.7z
Binary file not shown.
Binary file modified testdata/test.rar
Binary file not shown.
Binary file modified testdata/test.zip
Binary file not shown.
127 changes: 127 additions & 0 deletions unarr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)

Expand Down Expand Up @@ -49,3 +50,129 @@ func TestExtract(t *testing.T) {
a.Close()
}
}

func TestExtractFromMemory(t *testing.T) {
tmpdir, err := ioutil.TempDir(os.TempDir(), "unarr")
if err != nil {
t.Error(err)
}

defer os.RemoveAll(tmpdir)

files := []string{"test.zip", "test.rar", "test.7z"}

for _, f := range files {
data, err := ioutil.ReadFile(filepath.Join("testdata", f))
if err != nil {
t.Error(err)
}

a, err := NewArchiveFromMemory(data)
if err != nil {
t.Error(err)
}

a.Extract(tmpdir)
a.Close()
}
}

func TestReadAll(t *testing.T) {
exts := []string{"zip", "rar", "7z"}

for _, e := range exts {
a, err := NewArchive(filepath.Join("testdata", "test."+e))
if err != nil {
t.Error(err)
}

err = a.Entry()
if err != nil {
t.Error(err)
}

data, err := a.ReadAll()
if err != nil {
t.Error(err)
}

if strings.TrimSpace(string(data)) != "unarr" {
t.Error("Invalid data")
}

a.Close()
}
}

func TestReadAllFromMemory(t *testing.T) {
exts := []string{"zip", "rar", "7z"}

for _, e := range exts {
m, err := ioutil.ReadFile(filepath.Join("testdata", "test."+e))
if err != nil {
t.Error(err)
}

a, err := NewArchiveFromMemory(m)
if err != nil {
t.Error(err)
}

err = a.Entry()
if err != nil {
t.Error(err)
}

data, err := a.ReadAll()
if err != nil {
t.Error(err)
}

if strings.TrimSpace(string(data)) != "unarr" {
t.Error("Invalid data")
}

a.Close()
}
}

func TestEntryFor(t *testing.T) {
exts := []string{"zip", "rar", "7z"}

for _, e := range exts {
a, err := NewArchive(filepath.Join("testdata", "test."+e))
if err != nil {
t.Error(err)
}

err = a.EntryFor(e)
if err != nil {
t.Error(err)
}

data, err := a.ReadAll()
if err != nil {
t.Error(err)
}

if strings.TrimSpace(string(data)) != "unarr" {
t.Error("Invalid data")
}

a.Close()
}
}

func TestList(t *testing.T) {
files := []string{"test.zip", "test.rar", "test.7z"}

for _, f := range files {
a, err := NewArchive(filepath.Join("testdata", f))
if err != nil {
t.Error(err)
}

a.List()
a.Close()
}
}

0 comments on commit 0101eee

Please sign in to comment.