mirror of https://github.com/markbates/pkger.git
where is the harmony?
This commit is contained in:
parent
296799efbc
commit
6638215c4d
|
@ -2,7 +2,9 @@ package costello
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/markbates/pkger/pkging"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -16,12 +18,15 @@ 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,
|
||||
"CurrentTest": CurrentTest,
|
||||
"InfoTest": InfoTest,
|
||||
"MkdirAll": MkdirAllTest,
|
||||
"Open": OpenTest,
|
||||
"Stat": StatTest,
|
||||
"Create": CreateTest,
|
||||
"Current": CurrentTest,
|
||||
"Info": InfoTest,
|
||||
"MkdirAll": MkdirAllTest,
|
||||
"Remove": RemoveTest,
|
||||
"RemoveAll": RemoveAllTest,
|
||||
"Walk": WalkTest,
|
||||
}
|
||||
|
||||
pkg, err := fn(ref)
|
||||
|
@ -38,3 +43,13 @@ func All(t *testing.T, ref *Ref, fn AllFn) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func cmpFileInfo(t *testing.T, a os.FileInfo, b os.FileInfo) {
|
||||
t.Helper()
|
||||
r := require.New(t)
|
||||
r.Equal(a.IsDir(), b.IsDir())
|
||||
r.Equal(a.ModTime().Format(time.RFC3339), b.ModTime().Format(time.RFC3339))
|
||||
r.Equal(a.Mode(), b.Mode())
|
||||
r.Equal(a.Name(), b.Name())
|
||||
r.Equal(a.Size(), b.Size())
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/markbates/pkger/pkging"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -33,11 +32,7 @@ func openTest(name string, t *testing.T, ref *Ref, pkg pkging.Pkger) {
|
|||
psi, err := pf.Stat()
|
||||
r.NoError(err)
|
||||
|
||||
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))
|
||||
cmpFileInfo(t, osi, psi)
|
||||
|
||||
if osi.IsDir() {
|
||||
return
|
||||
|
|
|
@ -1 +1,24 @@
|
|||
package costello
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/pkging"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func RemoveTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
|
||||
r := require.New(t)
|
||||
|
||||
r.NoError(LoadRef(ref, pkg))
|
||||
|
||||
name := "/go.mod"
|
||||
|
||||
_, err := pkg.Stat(name)
|
||||
r.NoError(err)
|
||||
|
||||
r.NoError(pkg.Remove(name))
|
||||
|
||||
_, err = pkg.Stat(name)
|
||||
r.Error(err)
|
||||
}
|
||||
|
|
|
@ -1 +1,24 @@
|
|||
package costello
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/pkging"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func RemoveAllTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
|
||||
r := require.New(t)
|
||||
|
||||
r.NoError(LoadRef(ref, pkg))
|
||||
|
||||
name := "/public/assets"
|
||||
|
||||
_, err := pkg.Stat(name)
|
||||
r.NoError(err)
|
||||
|
||||
r.NoError(pkg.RemoveAll(name))
|
||||
|
||||
_, err = pkg.Stat(name)
|
||||
r.Error(err)
|
||||
}
|
||||
|
|
|
@ -1 +1,48 @@
|
|||
package costello
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/pkging"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func WalkTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
|
||||
r := require.New(t)
|
||||
|
||||
r.NoError(LoadRef(ref, pkg))
|
||||
|
||||
name := "public"
|
||||
|
||||
fp := filepath.Join(ref.Dir, name)
|
||||
|
||||
var exp []os.FileInfo
|
||||
err := filepath.Walk(fp, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
exp = append(exp, info)
|
||||
return nil
|
||||
})
|
||||
r.NoError(err)
|
||||
|
||||
var act []os.FileInfo
|
||||
err = pkg.Walk("/"+name, 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, info := range exp {
|
||||
cmpFileInfo(t, info, act[i])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package mem
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/markbates/pkger/pkging/costello"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_Pkger_MkdirAll(t *testing.T) {
|
||||
r := require.New(t)
|
||||
|
||||
ref, err := costello.NewRef()
|
||||
r.NoError(err)
|
||||
|
||||
pkg, err := New(ref.Info)
|
||||
r.NoError(err)
|
||||
|
||||
costello.MkdirAllTest(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_Remove(t *testing.T) {
|
||||
r := require.New(t)
|
||||
|
||||
ref, err := costello.NewRef()
|
||||
r.NoError(err)
|
||||
|
||||
pkg, err := New(ref.Info)
|
||||
r.NoError(err)
|
||||
|
||||
costello.RemoveTest(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_RemoveAll(t *testing.T) {
|
||||
r := require.New(t)
|
||||
|
||||
ref, err := costello.NewRef()
|
||||
r.NoError(err)
|
||||
|
||||
pkg, err := New(ref.Info)
|
||||
r.NoError(err)
|
||||
|
||||
costello.RemoveAllTest(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_Walk(t *testing.T) {
|
||||
r := require.New(t)
|
||||
|
||||
ref, err := costello.NewRef()
|
||||
r.NoError(err)
|
||||
|
||||
pkg, err := New(ref.Info)
|
||||
r.NoError(err)
|
||||
|
||||
costello.WalkTest(t, ref, pkg)
|
||||
}
|
Loading…
Reference in New Issue