forked from mirror/pkger
always fascinated by the weird edge of town
This commit is contained in:
parent
f79eafd257
commit
b9ac82f558
|
@ -9,9 +9,10 @@ import (
|
|||
|
||||
type AllFn func(ref *Ref) (pkging.Pkger, error)
|
||||
|
||||
func All(t *testing.T, fn AllFn) {
|
||||
func All(t *testing.T, ref *Ref, fn AllFn) {
|
||||
r := require.New(t)
|
||||
type tf func(*testing.T, pkging.Pkger)
|
||||
|
||||
type tf func(*testing.T, *Ref, pkging.Pkger)
|
||||
|
||||
tests := map[string]tf{
|
||||
"OpenTest": OpenTest,
|
||||
|
@ -19,15 +20,12 @@ func All(t *testing.T, fn AllFn) {
|
|||
"CreateTest": CreateTest,
|
||||
}
|
||||
|
||||
ref, err := NewRef()
|
||||
r.NoError(err)
|
||||
|
||||
for n, tt := range tests {
|
||||
t.Run(n, func(st *testing.T) {
|
||||
pkg, err := fn(ref)
|
||||
r.NoError(err)
|
||||
|
||||
tt(st, pkg)
|
||||
tt(st, ref, pkg)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -11,19 +11,16 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func CreateTest(t *testing.T, pkg pkging.Pkger) {
|
||||
func CreateTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
|
||||
r := require.New(t)
|
||||
|
||||
ref, err := NewRef()
|
||||
r.NoError(err)
|
||||
|
||||
const name = "create.test"
|
||||
|
||||
fp := filepath.Join(ref.Dir, name)
|
||||
os.RemoveAll(fp)
|
||||
defer os.RemoveAll(fp)
|
||||
|
||||
_, err = os.Stat(fp)
|
||||
_, err := os.Stat(fp)
|
||||
r.Error(err)
|
||||
|
||||
_, err = pkg.Stat(name)
|
||||
|
@ -44,5 +41,5 @@ func CreateTest(t *testing.T, pkg pkging.Pkger) {
|
|||
_, err = psf.Write(data)
|
||||
r.NoError(err)
|
||||
r.NoError(psf.Close())
|
||||
openTest(name, t, pkg)
|
||||
openTest(name, t, ref, pkg)
|
||||
}
|
||||
|
|
|
@ -12,16 +12,13 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func OpenTest(t *testing.T, pkg pkging.Pkger) {
|
||||
openTest("go.mod", t, pkg)
|
||||
func OpenTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
|
||||
openTest("go.mod", t, ref, pkg)
|
||||
}
|
||||
|
||||
func openTest(name string, t *testing.T, pkg pkging.Pkger) {
|
||||
func openTest(name string, t *testing.T, ref *Ref, pkg pkging.Pkger) {
|
||||
r := require.New(t)
|
||||
|
||||
ref, err := NewRef()
|
||||
r.NoError(err)
|
||||
|
||||
osf, err := os.Open(filepath.Join(ref.Dir, name))
|
||||
r.NoError(err)
|
||||
|
||||
|
|
|
@ -10,12 +10,9 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func StatTest(t *testing.T, pkg pkging.Pkger) {
|
||||
func StatTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
|
||||
r := require.New(t)
|
||||
|
||||
ref, err := NewRef()
|
||||
r.NoError(err)
|
||||
|
||||
osi, err := os.Stat(filepath.Join(ref.Dir, "go.mod"))
|
||||
r.NoError(err)
|
||||
|
||||
|
|
|
@ -16,5 +16,5 @@ func Test_Pkger_Create(t *testing.T) {
|
|||
pkg, err := New(ref.Info)
|
||||
r.NoError(err)
|
||||
|
||||
costello.CreateTest(t, pkg)
|
||||
costello.CreateTest(t, ref, pkg)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,11 @@ import (
|
|||
)
|
||||
|
||||
func Test_Pkger(t *testing.T) {
|
||||
costello.All(t, func(ref *costello.Ref) (pkging.Pkger, error) {
|
||||
ref, err := costello.NewRef()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
costello.All(t, ref, func(ref *costello.Ref) (pkging.Pkger, error) {
|
||||
return mem.New(ref.Info)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,5 +16,5 @@ func Test_Pkger_Open(t *testing.T) {
|
|||
pkg, err := New(ref.Info)
|
||||
r.NoError(err)
|
||||
|
||||
costello.OpenTest(t, pkg)
|
||||
costello.OpenTest(t, ref, pkg)
|
||||
}
|
||||
|
|
|
@ -16,5 +16,5 @@ func Test_Pkger_Stat(t *testing.T) {
|
|||
pkg, err := New(ref.Info)
|
||||
r.NoError(err)
|
||||
|
||||
costello.StatTest(t, pkg)
|
||||
costello.StatTest(t, ref, pkg)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue