pkger/pkging/mem/add_test.go

62 lines
1.1 KiB
Go
Raw Normal View History

2019-10-24 23:22:15 +03:00
package mem_test
import (
"os"
"path/filepath"
"testing"
2019-12-03 23:07:51 +03:00
"github.com/gobuffalo/here"
2019-10-24 23:22:15 +03:00
"github.com/markbates/pkger/pkging/mem"
"github.com/stretchr/testify/require"
)
func Test_Pkger_Add(t *testing.T) {
r := require.New(t)
2019-11-01 22:53:54 +03:00
cur, err := here.Package("github.com/markbates/pkger")
2019-10-24 23:22:15 +03:00
r.NoError(err)
2019-11-01 22:53:54 +03:00
pkg, err := mem.New(cur)
2019-10-24 23:22:15 +03:00
r.NoError(err)
var exp []os.FileInfo
2019-11-01 23:08:10 +03:00
root := filepath.Join(cur.Dir, "pkging", "pkgtest", "testdata", "ref")
2019-10-24 23:22:15 +03:00
err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
2019-11-01 22:53:54 +03:00
exp = append(exp, info)
2019-10-24 23:22:15 +03:00
return pkg.Add(f)
})
r.NoError(err)
var act []os.FileInfo
err = pkg.Walk("/", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
act = append(act, info)
return nil
})
r.NoError(err)
r.Len(act, len(exp))
for i, e := range exp {
a := act[i]
r.Equal(e.Name(), a.Name())
r.Equal(e.Size(), a.Size())
r.Equal(e.Mode(), a.Mode())
r.Equal(e.IsDir(), a.IsDir())
}
}