Skip to content

Commit

Permalink
Add unit tests of RegisterWithName()
Browse files Browse the repository at this point in the history
  • Loading branch information
shumon84 committed Jul 17, 2019
1 parent b9e67a7 commit 89153e0
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package fs
import (
"archive/zip"
"bytes"
"errors"
"io"
"io/ioutil"
"os"
Expand All @@ -39,6 +40,70 @@ type wantFile struct {
err error
}

func TestRegisterWithName(t *testing.T) {
tests := []struct {
description string
assetName string
zipData string
condition func() error
}{
{
description: "RegisterWithName() should set zipData with assetName to be key",
assetName: "file",
zipData: "file test",
condition: func() error {
data, ok := zipData["file"]
if !ok {
return errors.New("fail to register zipData")
}
if data != "file test" {
return errors.New("fail to register zipData[\"file\"]")
}
return nil
},
},
{
description: "zipData[\"default\"] should be able to open by Open()",
assetName: "default",
zipData: mustZipTree("../testdata/file"),
condition: func() error {
fs, err := New()
if err != nil {
return err
}
if _, err := fs.Open("/file.txt"); err != nil {
return err
}
return nil
},
},
{
description: "zipData[\"foo\"] should be able to open by OpenWithName(\"foo\")",
assetName: "foo",
zipData: mustZipTree("../testdata/file"),
condition: func() error {
fs, err := NewWithName("foo")
if err != nil {
return err
}
if _, err := fs.Open("/file.txt"); err != nil {
return err
}
return nil
},
},
}
for _, tc := range tests {
t.Run(tc.description, func(t *testing.T) {
RegisterWithName(tc.assetName, tc.zipData)
if err := tc.condition(); err != nil {
t.Error(err)
}
})
delete(zipData, tc.assetName)
}
}

func TestOpen(t *testing.T) {
fileTxtHeader := mustFileHeader("../testdata/file/file.txt")
pixelGifHeader := mustFileHeader("../testdata/image/pixel.gif")
Expand Down

0 comments on commit 89153e0

Please sign in to comment.