always fascinated by the weird edge of town

This commit is contained in:
Mark Bates 2019-10-30 16:56:22 -04:00
parent f79eafd257
commit b9ac82f558
8 changed files with 19 additions and 26 deletions

View File

@ -9,9 +9,10 @@ import (
type AllFn func(ref *Ref) (pkging.Pkger, error) 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) r := require.New(t)
type tf func(*testing.T, pkging.Pkger)
type tf func(*testing.T, *Ref, pkging.Pkger)
tests := map[string]tf{ tests := map[string]tf{
"OpenTest": OpenTest, "OpenTest": OpenTest,
@ -19,15 +20,12 @@ func All(t *testing.T, fn AllFn) {
"CreateTest": CreateTest, "CreateTest": CreateTest,
} }
ref, err := NewRef()
r.NoError(err)
for n, tt := range tests { for n, tt := range tests {
t.Run(n, func(st *testing.T) { t.Run(n, func(st *testing.T) {
pkg, err := fn(ref) pkg, err := fn(ref)
r.NoError(err) r.NoError(err)
tt(st, pkg) tt(st, ref, pkg)
}) })
} }

View File

@ -11,19 +11,16 @@ import (
"github.com/stretchr/testify/require" "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) r := require.New(t)
ref, err := NewRef()
r.NoError(err)
const name = "create.test" const name = "create.test"
fp := filepath.Join(ref.Dir, name) fp := filepath.Join(ref.Dir, name)
os.RemoveAll(fp) os.RemoveAll(fp)
defer os.RemoveAll(fp) defer os.RemoveAll(fp)
_, err = os.Stat(fp) _, err := os.Stat(fp)
r.Error(err) r.Error(err)
_, err = pkg.Stat(name) _, err = pkg.Stat(name)
@ -44,5 +41,5 @@ func CreateTest(t *testing.T, pkg pkging.Pkger) {
_, err = psf.Write(data) _, err = psf.Write(data)
r.NoError(err) r.NoError(err)
r.NoError(psf.Close()) r.NoError(psf.Close())
openTest(name, t, pkg) openTest(name, t, ref, pkg)
} }

View File

@ -12,16 +12,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func OpenTest(t *testing.T, pkg pkging.Pkger) { func OpenTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
openTest("go.mod", t, pkg) 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) r := require.New(t)
ref, err := NewRef()
r.NoError(err)
osf, err := os.Open(filepath.Join(ref.Dir, name)) osf, err := os.Open(filepath.Join(ref.Dir, name))
r.NoError(err) r.NoError(err)

View File

@ -10,12 +10,9 @@ import (
"github.com/stretchr/testify/require" "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) r := require.New(t)
ref, err := NewRef()
r.NoError(err)
osi, err := os.Stat(filepath.Join(ref.Dir, "go.mod")) osi, err := os.Stat(filepath.Join(ref.Dir, "go.mod"))
r.NoError(err) r.NoError(err)

View File

@ -16,5 +16,5 @@ func Test_Pkger_Create(t *testing.T) {
pkg, err := New(ref.Info) pkg, err := New(ref.Info)
r.NoError(err) r.NoError(err)
costello.CreateTest(t, pkg) costello.CreateTest(t, ref, pkg)
} }

View File

@ -9,7 +9,11 @@ import (
) )
func Test_Pkger(t *testing.T) { 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) return mem.New(ref.Info)
}) })
} }

View File

@ -16,5 +16,5 @@ func Test_Pkger_Open(t *testing.T) {
pkg, err := New(ref.Info) pkg, err := New(ref.Info)
r.NoError(err) r.NoError(err)
costello.OpenTest(t, pkg) costello.OpenTest(t, ref, pkg)
} }

View File

@ -16,5 +16,5 @@ func Test_Pkger_Stat(t *testing.T) {
pkg, err := New(ref.Info) pkg, err := New(ref.Info)
r.NoError(err) r.NoError(err)
costello.StatTest(t, pkg) costello.StatTest(t, ref, pkg)
} }