i will wait

This commit is contained in:
Mark Bates 2019-09-01 22:20:02 -04:00
parent 1c5d8bddb0
commit c970541180
3 changed files with 37 additions and 19 deletions

View File

@ -1,7 +1,6 @@
package memware package memware
import ( import (
"path/filepath"
"time" "time"
"github.com/markbates/pkger/pkging" "github.com/markbates/pkger/pkging"
@ -32,9 +31,5 @@ func (fx *Warehouse) Create(name string) (pkging.File, error) {
fx.files.Store(pt, f) fx.files.Store(pt, f)
dir := filepath.Dir(pt.Name)
if err := fx.MkdirAll(dir, 0644); err != nil {
return nil, err
}
return f, nil return f, nil
} }

View File

@ -58,9 +58,6 @@ func (fx *Warehouse) Create(name string) (pkging.File, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := fx.MkdirAll(filepath.Dir(name), 0755); err != nil {
return nil, err
}
f, err := os.Create(name) f, err := os.Create(name)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -88,10 +88,31 @@ func (s Suite) Clean() error {
func (s Suite) Test_Create(t *testing.T) { func (s Suite) Test_Create(t *testing.T) {
r := require.New(t) r := require.New(t)
cur, err := s.Current()
pt, err := s.Parse(mould)
r.NoError(err) r.NoError(err)
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)},
}
for _, tt := range table {
t.Run(tt.in, func(st *testing.T) {
r := require.New(st)
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) f, err := s.Create(pt.Name)
r.NoError(err) r.NoError(err)
r.Equal(pt.Name, f.Name()) r.Equal(pt.Name, f.Name())
@ -103,6 +124,8 @@ func (s Suite) Test_Create(t *testing.T) {
r.Equal(os.FileMode(0644), fi.Mode()) r.Equal(os.FileMode(0644), fi.Mode())
r.NotZero(fi.ModTime()) r.NotZero(fi.ModTime())
r.NoError(s.RemoveAll(pt.String())) r.NoError(s.RemoveAll(pt.String()))
})
}
} }
func (s Suite) Test_Current(t *testing.T) { 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(err)
r.NoError(s.RemoveAll(pt.String())) r.NoError(s.RemoveAll(pt.String()))
r.NoError(s.MkdirAll(filepath.Dir(pt.Name), 0755))
body := "!" + pt.String() body := "!" + pt.String()
@ -309,9 +333,11 @@ func (s Suite) Test_Stat_File(t *testing.T) {
r.NoError(err) r.NoError(err)
r.NoError(s.RemoveAll(pt.String())) r.NoError(s.RemoveAll(pt.String()))
r.NoError(s.MkdirAll(filepath.Dir(pt.Name), 0755))
f, err := s.Create(tt.in) f, err := s.Create(tt.in)
r.NoError(err) r.NoError(err)
_, err = io.Copy(f, strings.NewReader("!"+pt.String())) _, err = io.Copy(f, strings.NewReader("!"+pt.String()))
r.NoError(err) r.NoError(err)
r.NoError(f.Close()) r.NoError(f.Close())