paid to smile

This commit is contained in:
Mark Bates 2019-09-01 22:25:53 -04:00
parent c970541180
commit 9d7d315d44
2 changed files with 38 additions and 0 deletions

View File

@ -1,11 +1,13 @@
package memware
import (
"path/filepath"
"time"
"github.com/markbates/pkger/pkging"
)
// no such file or directory
func (fx *Warehouse) Create(name string) (pkging.File, error) {
pt, err := fx.Parse(name)
if err != nil {
@ -16,6 +18,10 @@ func (fx *Warehouse) Create(name string) (pkging.File, error) {
if err != nil {
return nil, err
}
if _, err := fx.Stat(filepath.Dir(pt.Name)); err != nil {
return nil, err
}
f := &File{
path: pt,
her: her,

View File

@ -128,6 +128,38 @@ func (s Suite) Test_Create(t *testing.T) {
}
}
func (s Suite) Test_Create_No_MkdirAll(t *testing.T) {
r := require.New(t)
cur, err := s.Current()
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()))
_, err = s.Create(pt.Name)
r.Error(err)
})
}
}
func (s Suite) Test_Current(t *testing.T) {
r := require.New(t)