From 9d7d315d44d25d6b52715d6d087e4cae365050a5 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Sun, 1 Sep 2019 22:25:53 -0400 Subject: [PATCH] paid to smile --- pkging/memware/create.go | 6 ++++++ pkging/waretest/suite.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/pkging/memware/create.go b/pkging/memware/create.go index c4b2d9c..4d7d9f3 100644 --- a/pkging/memware/create.go +++ b/pkging/memware/create.go @@ -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, diff --git a/pkging/waretest/suite.go b/pkging/waretest/suite.go index 8bef502..e760a98 100644 --- a/pkging/waretest/suite.go +++ b/pkging/waretest/suite.go @@ -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)