diff --git a/pkging/memware/create.go b/pkging/memware/create.go index eccef75..c4b2d9c 100644 --- a/pkging/memware/create.go +++ b/pkging/memware/create.go @@ -1,7 +1,6 @@ package memware import ( - "path/filepath" "time" "github.com/markbates/pkger/pkging" @@ -32,9 +31,5 @@ func (fx *Warehouse) Create(name string) (pkging.File, error) { fx.files.Store(pt, f) - dir := filepath.Dir(pt.Name) - if err := fx.MkdirAll(dir, 0644); err != nil { - return nil, err - } return f, nil } diff --git a/pkging/osware/warehouse.go b/pkging/osware/warehouse.go index f0e75f4..9ad054e 100644 --- a/pkging/osware/warehouse.go +++ b/pkging/osware/warehouse.go @@ -58,9 +58,6 @@ func (fx *Warehouse) Create(name string) (pkging.File, error) { if err != nil { return nil, err } - if err := fx.MkdirAll(filepath.Dir(name), 0755); err != nil { - return nil, err - } f, err := os.Create(name) if err != nil { return nil, err diff --git a/pkging/waretest/suite.go b/pkging/waretest/suite.go index 48f9c87..8bef502 100644 --- a/pkging/waretest/suite.go +++ b/pkging/waretest/suite.go @@ -88,21 +88,44 @@ func (s Suite) Clean() error { func (s Suite) Test_Create(t *testing.T) { r := require.New(t) - - pt, err := s.Parse(mould) + cur, err := s.Current() r.NoError(err) - f, err := s.Create(pt.Name) - r.NoError(err) - r.Equal(pt.Name, f.Name()) + ip := cur.ImportPath + table := []struct { + in string + }{ + {in: mould}, + {in: ":" + mould}, + {in: ip + ":" + mould}, + {in: filepath.Dir(mould)}, + {in: ":" + filepath.Dir(mould)}, + {in: ip + ":" + filepath.Dir(mould)}, + } - fi, err := f.Stat() - r.NoError(err) + for _, tt := range table { + t.Run(tt.in, func(st *testing.T) { + r := require.New(st) - r.Equal(pt.Name, fi.Name()) - r.Equal(os.FileMode(0644), fi.Mode()) - r.NotZero(fi.ModTime()) - r.NoError(s.RemoveAll(pt.String())) + pt, err := s.Parse(tt.in) + r.NoError(err) + + r.NoError(s.RemoveAll(pt.String())) + r.NoError(s.MkdirAll(filepath.Dir(pt.Name), 0755)) + + f, err := s.Create(pt.Name) + r.NoError(err) + r.Equal(pt.Name, f.Name()) + + fi, err := f.Stat() + r.NoError(err) + + r.Equal(pt.Name, fi.Name()) + r.Equal(os.FileMode(0644), fi.Mode()) + r.NotZero(fi.ModTime()) + r.NoError(s.RemoveAll(pt.String())) + }) + } } func (s Suite) Test_Current(t *testing.T) { @@ -154,6 +177,7 @@ func (s Suite) Test_Open_File(t *testing.T) { r.NoError(err) r.NoError(s.RemoveAll(pt.String())) + r.NoError(s.MkdirAll(filepath.Dir(pt.Name), 0755)) body := "!" + pt.String() @@ -309,9 +333,11 @@ func (s Suite) Test_Stat_File(t *testing.T) { r.NoError(err) r.NoError(s.RemoveAll(pt.String())) + r.NoError(s.MkdirAll(filepath.Dir(pt.Name), 0755)) f, err := s.Create(tt.in) r.NoError(err) + _, err = io.Copy(f, strings.NewReader("!"+pt.String())) r.NoError(err) r.NoError(f.Close())