even though I've seen the movie

This commit is contained in:
Mark Bates 2019-10-30 17:15:49 -04:00
parent b9ac82f558
commit 296799efbc
7 changed files with 138 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package costello
import (
"fmt"
"testing"
"github.com/markbates/pkger/pkging"
@ -18,10 +19,17 @@ func All(t *testing.T, ref *Ref, fn AllFn) {
"OpenTest": OpenTest,
"StatTest": StatTest,
"CreateTest": CreateTest,
"CurrentTest": CurrentTest,
"InfoTest": InfoTest,
"MkdirAll": MkdirAllTest,
}
pkg, err := fn(ref)
r.NoError(err)
for n, tt := range tests {
t.Run(n, func(st *testing.T) {
t.Run(fmt.Sprintf("%T/%s", pkg, n), func(st *testing.T) {
st.Parallel()
pkg, err := fn(ref)
r.NoError(err)

View File

@ -1 +1,16 @@
package costello
import (
"testing"
"github.com/markbates/pkger/pkging"
"github.com/stretchr/testify/require"
)
func CurrentTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
r := require.New(t)
cur, err := pkg.Current()
r.NoError(err)
r.Equal(ref.Info, cur)
}

View File

@ -1 +1,17 @@
package costello
import (
"testing"
"github.com/markbates/pkger/pkging"
"github.com/stretchr/testify/require"
)
func InfoTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
r := require.New(t)
info, err := pkg.Info("app")
r.NoError(err)
r.Equal(ref.Info, info)
}

View File

@ -1 +1,42 @@
package costello
import (
"os"
"path"
"path/filepath"
"strings"
"testing"
"github.com/markbates/pkger/pkging"
"github.com/stretchr/testify/require"
)
func MkdirAllTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
r := require.New(t)
parts := []string{"all", "this", "useless", "beauty"}
fp := ref.Dir
for _, part := range parts {
fp = filepath.Join(fp, part)
}
os.RemoveAll(fp)
defer os.RemoveAll(fp)
_, err := os.Stat(fp)
r.Error(err)
name := path.Join(parts...)
if !strings.HasPrefix(name, "/") {
name = "/" + name
}
_, err = pkg.Stat(name)
r.Error(err)
r.NoError(os.MkdirAll(fp, 0755))
r.NoError(pkg.MkdirAll(name, 0755))
openTest(name, t, ref, pkg)
}

View File

@ -25,10 +25,6 @@ func openTest(name string, t *testing.T, ref *Ref, pkg pkging.Pkger) {
osi, err := osf.Stat()
r.NoError(err)
osb, err := ioutil.ReadAll(osf)
r.NoError(err)
r.NoError(osf.Close())
r.NoError(LoadRef(ref, pkg))
pf, err := pkg.Open(fmt.Sprintf("/%s", name))
@ -37,13 +33,23 @@ func openTest(name string, t *testing.T, ref *Ref, pkg pkging.Pkger) {
psi, err := pf.Stat()
r.NoError(err)
psb, err := ioutil.ReadAll(pf)
r.NoError(err)
r.NoError(pf.Close())
r.Equal(osi.IsDir(), psi.IsDir())
r.Equal(osi.Name(), psi.Name())
r.Equal(osi.Mode(), psi.Mode())
r.Equal(osi.Size(), psi.Size())
r.Equal(osi.ModTime().Format(time.RFC3339), psi.ModTime().Format(time.RFC3339))
if osi.IsDir() {
return
}
osb, err := ioutil.ReadAll(osf)
r.NoError(err)
r.NoError(osf.Close())
psb, err := ioutil.ReadAll(pf)
r.NoError(err)
r.NoError(pf.Close())
r.Equal(osb, psb)
}

View File

@ -0,0 +1,20 @@
package mem
import (
"testing"
"github.com/markbates/pkger/pkging/costello"
"github.com/stretchr/testify/require"
)
func Test_Pkger_Current(t *testing.T) {
r := require.New(t)
ref, err := costello.NewRef()
r.NoError(err)
pkg, err := New(ref.Info)
r.NoError(err)
costello.CurrentTest(t, ref, pkg)
}

20
pkging/mem/info_test.go Normal file
View File

@ -0,0 +1,20 @@
package mem
import (
"testing"
"github.com/markbates/pkger/pkging/costello"
"github.com/stretchr/testify/require"
)
func Test_Pkger_Info(t *testing.T) {
r := require.New(t)
ref, err := costello.NewRef()
r.NoError(err)
pkg, err := New(ref.Info)
r.NoError(err)
costello.InfoTest(t, ref, pkg)
}