mirror of https://github.com/markbates/pkger.git
even though I've seen the movie
This commit is contained in:
parent
b9ac82f558
commit
296799efbc
|
@ -1,6 +1,7 @@
|
|||
package costello
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/pkging"
|
||||
|
@ -15,13 +16,20 @@ func All(t *testing.T, ref *Ref, fn AllFn) {
|
|||
type tf func(*testing.T, *Ref, pkging.Pkger)
|
||||
|
||||
tests := map[string]tf{
|
||||
"OpenTest": OpenTest,
|
||||
"StatTest": StatTest,
|
||||
"CreateTest": CreateTest,
|
||||
"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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue