From b9ac82f558b71f4d5b10eb49857983a64e15da47 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Wed, 30 Oct 2019 16:56:22 -0400 Subject: [PATCH] always fascinated by the weird edge of town --- pkging/costello/costello.go | 10 ++++------ pkging/costello/create.go | 9 +++------ pkging/costello/open.go | 9 +++------ pkging/costello/stat.go | 5 +---- pkging/mem/create_test.go | 2 +- pkging/mem/mem_test.go | 6 +++++- pkging/mem/open_test.go | 2 +- pkging/mem/stat_test.go | 2 +- 8 files changed, 19 insertions(+), 26 deletions(-) diff --git a/pkging/costello/costello.go b/pkging/costello/costello.go index ebe1b2e..d4a2fc8 100644 --- a/pkging/costello/costello.go +++ b/pkging/costello/costello.go @@ -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) }) } diff --git a/pkging/costello/create.go b/pkging/costello/create.go index 0a95463..0c5df6e 100644 --- a/pkging/costello/create.go +++ b/pkging/costello/create.go @@ -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) } diff --git a/pkging/costello/open.go b/pkging/costello/open.go index bf632c4..4eebb0e 100644 --- a/pkging/costello/open.go +++ b/pkging/costello/open.go @@ -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) diff --git a/pkging/costello/stat.go b/pkging/costello/stat.go index 442788b..dbc2fa2 100644 --- a/pkging/costello/stat.go +++ b/pkging/costello/stat.go @@ -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) diff --git a/pkging/mem/create_test.go b/pkging/mem/create_test.go index 7205a08..de56d6e 100644 --- a/pkging/mem/create_test.go +++ b/pkging/mem/create_test.go @@ -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) } diff --git a/pkging/mem/mem_test.go b/pkging/mem/mem_test.go index e18817f..90ed9bc 100644 --- a/pkging/mem/mem_test.go +++ b/pkging/mem/mem_test.go @@ -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) }) } diff --git a/pkging/mem/open_test.go b/pkging/mem/open_test.go index d3f25a5..a9ca653 100644 --- a/pkging/mem/open_test.go +++ b/pkging/mem/open_test.go @@ -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) } diff --git a/pkging/mem/stat_test.go b/pkging/mem/stat_test.go index 4bf9e89..88cb02e 100644 --- a/pkging/mem/stat_test.go +++ b/pkging/mem/stat_test.go @@ -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) }