From 3d94a20bbfff81fd4d9cf9bf16681dc321c9e435 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Sun, 1 Sep 2019 18:02:45 -0400 Subject: [PATCH] bottles and flowers --- fs/fstest/file.go | 12 ------- fs/osware/warehouse_test.go | 24 ------------- internal/maps/files.go | 44 ++++++++++++------------ internal/maps/paths.go | 30 ++++++++-------- {fs => pkging}/file.go | 2 +- {fs => pkging}/info.go | 2 +- {fs => pkging}/memware/create.go | 12 +++---- {fs => pkging}/memware/create_test.go | 0 {fs => pkging}/memware/file.go | 36 +++++++++---------- {fs => pkging}/memware/file_test.go | 0 {fs => pkging}/memware/http.go | 0 {fs => pkging}/memware/http_test.go | 0 {fs => pkging}/memware/json.go | 4 +-- {fs => pkging}/memware/json_test.go | 0 {fs => pkging}/memware/mkdirall.go | 16 ++++----- {fs => pkging}/memware/mkdirall_test.go | 0 {fs => pkging}/memware/open.go | 14 ++++---- {fs => pkging}/memware/open_test.go | 0 {fs => pkging}/memware/stat.go | 0 {fs => pkging}/memware/stat_test.go | 0 {fs => pkging}/memware/walk.go | 4 +-- {fs => pkging}/memware/walk_test.go | 0 {fs => pkging}/memware/warehouse.go | 8 ++--- {fs => pkging}/memware/warehouse_test.go | 8 ++--- {fs => pkging}/mod_time.go | 2 +- {fs => pkging}/osware/file.go | 28 +++++++-------- {fs => pkging}/osware/warehouse.go | 16 ++++----- pkging/osware/warehouse_test.go | 24 +++++++++++++ {fs => pkging}/path.go | 2 +- {fs => pkging}/warehouse.go | 2 +- pkging/waretest/file.go | 12 +++++++ {fs/fstest => pkging/waretest}/fstest.go | 6 ++-- {fs/fstest => pkging/waretest}/suite.go | 30 ++++++++-------- 33 files changed, 169 insertions(+), 169 deletions(-) delete mode 100644 fs/fstest/file.go delete mode 100644 fs/osware/warehouse_test.go rename {fs => pkging}/file.go (96%) rename {fs => pkging}/info.go (99%) rename {fs => pkging}/memware/create.go (66%) rename {fs => pkging}/memware/create_test.go (100%) rename {fs => pkging}/memware/file.go (79%) rename {fs => pkging}/memware/file_test.go (100%) rename {fs => pkging}/memware/http.go (100%) rename {fs => pkging}/memware/http_test.go (100%) rename {fs => pkging}/memware/json.go (94%) rename {fs => pkging}/memware/json_test.go (100%) rename {fs => pkging}/memware/mkdirall.go (78%) rename {fs => pkging}/memware/mkdirall_test.go (100%) rename {fs => pkging}/memware/open.go (59%) rename {fs => pkging}/memware/open_test.go (100%) rename {fs => pkging}/memware/stat.go (100%) rename {fs => pkging}/memware/stat_test.go (100%) rename {fs => pkging}/memware/walk.go (83%) rename {fs => pkging}/memware/walk_test.go (100%) rename {fs => pkging}/memware/warehouse.go (91%) rename {fs => pkging}/memware/warehouse_test.go (66%) rename {fs => pkging}/mod_time.go (96%) rename {fs => pkging}/osware/file.go (69%) rename {fs => pkging}/osware/warehouse.go (86%) create mode 100644 pkging/osware/warehouse_test.go rename {fs => pkging}/path.go (97%) rename {fs => pkging}/warehouse.go (99%) create mode 100644 pkging/waretest/file.go rename {fs/fstest => pkging/waretest}/fstest.go (77%) rename {fs/fstest => pkging/waretest}/suite.go (85%) diff --git a/fs/fstest/file.go b/fs/fstest/file.go deleted file mode 100644 index 7c61646..0000000 --- a/fs/fstest/file.go +++ /dev/null @@ -1,12 +0,0 @@ -package fstest - -import ( - "github.com/markbates/pkger/fs" -) - -type TestFile struct { - Name string - Path fs.Path -} - -type TestFiles map[fs.Path]TestFile diff --git a/fs/osware/warehouse_test.go b/fs/osware/warehouse_test.go deleted file mode 100644 index 398934e..0000000 --- a/fs/osware/warehouse_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package hdware - -import ( - "path/filepath" - "testing" - - "github.com/markbates/pkger/fs/fstest" - "github.com/stretchr/testify/require" -) - -func Test_Warehouse(t *testing.T) { - r := require.New(t) - - myfs, err := New() - r.NoError(err) - - myfs.current.Dir = filepath.Join(myfs.current.Dir, ".fstest") - myfs.paths.Current = myfs.current - - suite, err := fstest.NewSuite(myfs) - r.NoError(err) - - suite.Test(t) -} diff --git a/internal/maps/files.go b/internal/maps/files.go index c30170f..ddd3ccd 100644 --- a/internal/maps/files.go +++ b/internal/maps/files.go @@ -8,12 +8,12 @@ import ( "sort" "sync" - "github.com/markbates/pkger/fs" + "github.com/markbates/pkger/pkging" ) // Files wraps sync.Map and uses the following types: -// key: fs.Path -// value: fs.File +// key: pkging.Path +// value: pkging.File type Files struct { data *sync.Map once *sync.Once @@ -52,13 +52,13 @@ func (m *Files) MarshalJSON() ([]byte, error) { } func (m *Files) UnmarshalJSON(b []byte) error { - mm := map[string]fs.File{} + mm := map[string]pkging.File{} if err := json.Unmarshal(b, &mm); err != nil { return err } for k, v := range mm { - var pt fs.Path + var pt pkging.Path if err := json.Unmarshal([]byte(k), &pt); err != nil { return err } @@ -68,34 +68,34 @@ func (m *Files) UnmarshalJSON(b []byte) error { } // Delete the key from the map -func (m *Files) Delete(key fs.Path) { +func (m *Files) Delete(key pkging.Path) { m.Data().Delete(key) } // Load the key from the map. -// Returns fs.File or bool. +// Returns pkging.File or bool. // A false return indicates either the key was not found -// or the value is not of type fs.File -func (m *Files) Load(key fs.Path) (fs.File, bool) { +// or the value is not of type pkging.File +func (m *Files) Load(key pkging.Path) (pkging.File, bool) { i, ok := m.Data().Load(key) if !ok { return nil, false } - s, ok := i.(fs.File) + s, ok := i.(pkging.File) return s, ok } // LoadOrStore will return an existing key or // store the value if not already in the map -func (m *Files) LoadOrStore(key fs.Path, value fs.File) (fs.File, bool) { +func (m *Files) LoadOrStore(key pkging.Path, value pkging.File) (pkging.File, bool) { i, _ := m.Data().LoadOrStore(key, value) - s, ok := i.(fs.File) + s, ok := i.(pkging.File) return s, ok } // LoadOr will return an existing key or // run the function and store the results -func (m *Files) LoadOr(key fs.Path, fn func(*Files) (fs.File, bool)) (fs.File, bool) { +func (m *Files) LoadOr(key pkging.Path, fn func(*Files) (pkging.File, bool)) (pkging.File, bool) { i, ok := m.Load(key) if ok { return i, ok @@ -108,14 +108,14 @@ func (m *Files) LoadOr(key fs.Path, fn func(*Files) (fs.File, bool)) (fs.File, b return i, false } -// Range over the fs.File values in the map -func (m *Files) Range(f func(key fs.Path, value fs.File) bool) { +// Range over the pkging.File values in the map +func (m *Files) Range(f func(key pkging.Path, value pkging.File) bool) { m.Data().Range(func(k, v interface{}) bool { - key, ok := k.(fs.Path) + key, ok := k.(pkging.Path) if !ok { return false } - value, ok := v.(fs.File) + value, ok := v.(pkging.File) if !ok { return false } @@ -123,15 +123,15 @@ func (m *Files) Range(f func(key fs.Path, value fs.File) bool) { }) } -// Store a fs.File in the map -func (m *Files) Store(key fs.Path, value fs.File) { +// Store a pkging.File in the map +func (m *Files) Store(key pkging.Path, value pkging.File) { m.Data().Store(key, value) } // Keys returns a list of keys in the map -func (m *Files) Keys() []fs.Path { - var keys []fs.Path - m.Range(func(key fs.Path, value fs.File) bool { +func (m *Files) Keys() []pkging.Path { + var keys []pkging.Path + m.Range(func(key pkging.Path, value pkging.File) bool { keys = append(keys, key) return true }) diff --git a/internal/maps/paths.go b/internal/maps/paths.go index aee61f8..e114c5e 100644 --- a/internal/maps/paths.go +++ b/internal/maps/paths.go @@ -10,8 +10,8 @@ import ( "strings" "sync" - "github.com/markbates/pkger/fs" "github.com/markbates/pkger/here" + "github.com/markbates/pkger/pkging" ) // Paths wraps sync.Map and uses the following types: @@ -45,7 +45,7 @@ func (m *Paths) MarshalJSON() ([]byte, error) { } func (m *Paths) UnmarshalJSON(b []byte) error { - mm := map[string]fs.Path{} + mm := map[string]pkging.Path{} if err := json.Unmarshal(b, &mm); err != nil { return err @@ -65,26 +65,26 @@ func (m *Paths) Delete(key string) { // Returns Path or bool. // A false return indicates either the key was not found // or the value is not of type Path -func (m *Paths) Load(key string) (fs.Path, bool) { +func (m *Paths) Load(key string) (pkging.Path, bool) { i, ok := m.Data().Load(key) if !ok { - return fs.Path{}, false + return pkging.Path{}, false } - s, ok := i.(fs.Path) + s, ok := i.(pkging.Path) return s, ok } // LoadOrStore will return an existing key or // store the value if not already in the map -func (m *Paths) LoadOrStore(key string, value fs.Path) (fs.Path, bool) { +func (m *Paths) LoadOrStore(key string, value pkging.Path) (pkging.Path, bool) { i, _ := m.Data().LoadOrStore(key, value) - s, ok := i.(fs.Path) + s, ok := i.(pkging.Path) return s, ok } // LoadOr will return an existing key or // run the function and store the results -func (m *Paths) LoadOr(key string, fn func(*Paths) (fs.Path, bool)) (fs.Path, bool) { +func (m *Paths) LoadOr(key string, fn func(*Paths) (pkging.Path, bool)) (pkging.Path, bool) { i, ok := m.Load(key) if ok { return i, ok @@ -98,13 +98,13 @@ func (m *Paths) LoadOr(key string, fn func(*Paths) (fs.Path, bool)) (fs.Path, bo } // Range over the Path values in the map -func (m *Paths) Range(f func(key string, value fs.Path) bool) { +func (m *Paths) Range(f func(key string, value pkging.Path) bool) { m.Data().Range(func(k, v interface{}) bool { key, ok := k.(string) if !ok { return false } - value, ok := v.(fs.Path) + value, ok := v.(pkging.Path) if !ok { return false } @@ -113,14 +113,14 @@ func (m *Paths) Range(f func(key string, value fs.Path) bool) { } // Store a Path in the map -func (m *Paths) Store(key string, value fs.Path) { +func (m *Paths) Store(key string, value pkging.Path) { m.Data().Store(key, value) } // Keys returns a list of keys in the map func (m *Paths) Keys() []string { var keys []string - m.Range(func(key string, value fs.Path) bool { + m.Range(func(key string, value pkging.Path) bool { keys = append(keys, key) return true }) @@ -128,7 +128,7 @@ func (m *Paths) Keys() []string { return keys } -func (m *Paths) Parse(p string) (fs.Path, error) { +func (m *Paths) Parse(p string) (pkging.Path, error) { p = strings.Replace(p, "\\", "/", -1) p = strings.TrimSpace(p) @@ -156,8 +156,8 @@ func (m *Paths) Parse(p string) (fs.Path, error) { var pathrx = regexp.MustCompile("([^:]+)(:(/.+))?") -func (m *Paths) build(p, pkg, name string) (fs.Path, error) { - pt := fs.Path{ +func (m *Paths) build(p, pkg, name string) (pkging.Path, error) { + pt := pkging.Path{ Pkg: pkg, Name: name, } diff --git a/fs/file.go b/pkging/file.go similarity index 96% rename from fs/file.go rename to pkging/file.go index 428c51f..1fad69d 100644 --- a/fs/file.go +++ b/pkging/file.go @@ -1,4 +1,4 @@ -package fs +package pkging import ( "net/http" diff --git a/fs/info.go b/pkging/info.go similarity index 99% rename from fs/info.go rename to pkging/info.go index 87db439..3e6e97a 100644 --- a/fs/info.go +++ b/pkging/info.go @@ -1,4 +1,4 @@ -package fs +package pkging import ( "encoding/json" diff --git a/fs/memware/create.go b/pkging/memware/create.go similarity index 66% rename from fs/memware/create.go rename to pkging/memware/create.go index 55fd12f..eccef75 100644 --- a/fs/memware/create.go +++ b/pkging/memware/create.go @@ -4,10 +4,10 @@ import ( "path/filepath" "time" - "github.com/markbates/pkger/fs" + "github.com/markbates/pkger/pkging" ) -func (fx *Warehouse) Create(name string) (fs.File, error) { +func (fx *Warehouse) Create(name string) (pkging.File, error) { pt, err := fx.Parse(name) if err != nil { return nil, err @@ -20,14 +20,14 @@ func (fx *Warehouse) Create(name string) (fs.File, error) { f := &File{ path: pt, her: her, - info: &fs.FileInfo{ - Details: fs.Details{ + info: &pkging.FileInfo{ + Details: pkging.Details{ Name: pt.Name, Mode: 0644, - ModTime: fs.ModTime(time.Now()), + ModTime: pkging.ModTime(time.Now()), }, }, - fs: fx, + pkging: fx, } fx.files.Store(pt, f) diff --git a/fs/memware/create_test.go b/pkging/memware/create_test.go similarity index 100% rename from fs/memware/create_test.go rename to pkging/memware/create_test.go diff --git a/fs/memware/file.go b/pkging/memware/file.go similarity index 79% rename from fs/memware/file.go rename to pkging/memware/file.go index 7e156d0..b5b89f5 100644 --- a/fs/memware/file.go +++ b/pkging/memware/file.go @@ -11,28 +11,28 @@ import ( "strings" "time" - "github.com/markbates/pkger/fs" "github.com/markbates/pkger/here" + "github.com/markbates/pkger/pkging" ) const timeFmt = time.RFC3339Nano -var _ fs.File = &File{} +var _ pkging.File = &File{} type File struct { - info *fs.FileInfo + info *pkging.FileInfo her here.Info - path fs.Path + path pkging.Path data []byte - parent fs.Path + parent pkging.Path writer *bytes.Buffer reader io.Reader - fs fs.Warehouse + pkging pkging.Warehouse } -func (f *File) Seek(offset int64, whence int) (int64, error) { +func (f *File) Seek(ofpkginget int64, whence int) (int64, error) { if sk, ok := f.reader.(io.Seeker); ok { - return sk.Seek(offset, whence) + return sk.Seek(ofpkginget, whence) } return 0, nil } @@ -58,7 +58,7 @@ func (f *File) Close() error { fi := f.info fi.Details.Size = int64(len(f.data)) - fi.Details.ModTime = fs.ModTime(time.Now()) + fi.Details.ModTime = pkging.ModTime(time.Now()) f.info = fi return nil } @@ -99,10 +99,10 @@ func (f File) Name() string { } func (f File) Abs() (string, error) { - return f.fs.AbsPath(f.Path()) + return f.pkging.AbsPath(f.Path()) } -func (f File) Path() fs.Path { +func (f File) Path() pkging.Path { return f.path } @@ -133,7 +133,7 @@ func (f File) Format(st fmt.State, verb rune) { func (f *File) Readdir(count int) ([]os.FileInfo, error) { var infos []os.FileInfo root := f.Path().String() - err := f.fs.Walk(root, func(path string, info os.FileInfo, err error) error { + err := f.pkging.Walk(root, func(path string, info os.FileInfo, err error) error { if err != nil { return err } @@ -142,7 +142,7 @@ func (f *File) Readdir(count int) ([]os.FileInfo, error) { return io.EOF } - pt, err := f.fs.Parse(path) + pt, err := f.pkging.Parse(path) if err != nil { return err } @@ -150,7 +150,7 @@ func (f *File) Readdir(count int) ([]os.FileInfo, error) { return nil } // if f.parent.Name != "/" { - info = fs.WithName(strings.TrimPrefix(info.Name(), f.parent.Name), info) + info = pkging.WithName(strings.TrimPrefix(info.Name(), f.parent.Name), info) // } infos = append(infos, info) return nil @@ -169,7 +169,7 @@ func (f *File) Readdir(count int) ([]os.FileInfo, error) { } func (f *File) Open(name string) (http.File, error) { - pt, err := f.fs.Parse(name) + pt, err := f.pkging.Parse(name) if err != nil { return nil, err } @@ -180,7 +180,7 @@ func (f *File) Open(name string) (http.File, error) { pt.Name = path.Join(f.Path().Name, pt.Name) - di, err := f.fs.Open(pt.String()) + di, err := f.pkging.Open(pt.String()) if err != nil { return nil, err } @@ -191,11 +191,11 @@ func (f *File) Open(name string) (http.File, error) { } if fi.IsDir() { d2 := &File{ - info: fs.NewFileInfo(fi), + info: pkging.NewFileInfo(fi), her: di.Info(), path: pt, parent: f.path, - fs: f.fs, + pkging: f.pkging, } di = d2 } diff --git a/fs/memware/file_test.go b/pkging/memware/file_test.go similarity index 100% rename from fs/memware/file_test.go rename to pkging/memware/file_test.go diff --git a/fs/memware/http.go b/pkging/memware/http.go similarity index 100% rename from fs/memware/http.go rename to pkging/memware/http.go diff --git a/fs/memware/http_test.go b/pkging/memware/http_test.go similarity index 100% rename from fs/memware/http_test.go rename to pkging/memware/http_test.go diff --git a/fs/memware/json.go b/pkging/memware/json.go similarity index 94% rename from fs/memware/json.go rename to pkging/memware/json.go index 90a9d41..717d830 100644 --- a/fs/memware/json.go +++ b/pkging/memware/json.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" - "github.com/markbates/pkger/fs" + "github.com/markbates/pkger/pkging" ) func (f File) MarshalJSON() ([]byte, error) { @@ -29,7 +29,7 @@ func (f *File) UnmarshalJSON(b []byte) error { return fmt.Errorf("missing info") } - f.info = &fs.FileInfo{} + f.info = &pkging.FileInfo{} if err := json.Unmarshal(info, f.info); err != nil { return err } diff --git a/fs/memware/json_test.go b/pkging/memware/json_test.go similarity index 100% rename from fs/memware/json_test.go rename to pkging/memware/json_test.go diff --git a/fs/memware/mkdirall.go b/pkging/memware/mkdirall.go similarity index 78% rename from fs/memware/mkdirall.go rename to pkging/memware/mkdirall.go index e426800..a3efc18 100644 --- a/fs/memware/mkdirall.go +++ b/pkging/memware/mkdirall.go @@ -5,7 +5,7 @@ import ( "path/filepath" "time" - "github.com/markbates/pkger/fs" + "github.com/markbates/pkger/pkging" ) func (fx *Warehouse) MkdirAll(p string, perm os.FileMode) error { @@ -20,7 +20,7 @@ func (fx *Warehouse) MkdirAll(p string, perm os.FileMode) error { return err } for root != "" { - pt := fs.Path{ + pt := pkging.Path{ Pkg: path.Pkg, Name: root, } @@ -32,14 +32,14 @@ func (fx *Warehouse) MkdirAll(p string, perm os.FileMode) error { continue } f := &File{ - fs: fx, - path: pt, - her: cur, - info: &fs.FileInfo{ - Details: fs.Details{ + pkging: fx, + path: pt, + her: cur, + info: &pkging.FileInfo{ + Details: pkging.Details{ Name: pt.Name, Mode: perm, - ModTime: fs.ModTime(time.Now()), + ModTime: pkging.ModTime(time.Now()), }, }, } diff --git a/fs/memware/mkdirall_test.go b/pkging/memware/mkdirall_test.go similarity index 100% rename from fs/memware/mkdirall_test.go rename to pkging/memware/mkdirall_test.go diff --git a/fs/memware/open.go b/pkging/memware/open.go similarity index 59% rename from fs/memware/open.go rename to pkging/memware/open.go index d4e5a7e..62ff730 100644 --- a/fs/memware/open.go +++ b/pkging/memware/open.go @@ -3,10 +3,10 @@ package memware import ( "fmt" - "github.com/markbates/pkger/fs" + "github.com/markbates/pkger/pkging" ) -func (fx *Warehouse) Open(name string) (fs.File, error) { +func (fx *Warehouse) Open(name string) (pkging.File, error) { pt, err := fx.Parse(name) if err != nil { return nil, err @@ -21,11 +21,11 @@ func (fx *Warehouse) Open(name string) (fs.File, error) { return nil, fmt.Errorf("could not open %s", name) } nf := &File{ - fs: fx, - info: fs.WithName(f.info.Name(), f.info), - path: f.path, - data: f.data, - her: f.her, + pkging: fx, + info: pkging.WithName(f.info.Name(), f.info), + path: f.path, + data: f.data, + her: f.her, } return nf, nil diff --git a/fs/memware/open_test.go b/pkging/memware/open_test.go similarity index 100% rename from fs/memware/open_test.go rename to pkging/memware/open_test.go diff --git a/fs/memware/stat.go b/pkging/memware/stat.go similarity index 100% rename from fs/memware/stat.go rename to pkging/memware/stat.go diff --git a/fs/memware/stat_test.go b/pkging/memware/stat_test.go similarity index 100% rename from fs/memware/stat_test.go rename to pkging/memware/stat_test.go diff --git a/fs/memware/walk.go b/pkging/memware/walk.go similarity index 83% rename from fs/memware/walk.go rename to pkging/memware/walk.go index 2836ff6..577fb48 100644 --- a/fs/memware/walk.go +++ b/pkging/memware/walk.go @@ -5,7 +5,7 @@ import ( "path/filepath" "strings" - "github.com/markbates/pkger/fs" + "github.com/markbates/pkger/pkging" ) func (f *Warehouse) Walk(p string, wf filepath.WalkFunc) error { @@ -28,7 +28,7 @@ func (f *Warehouse) Walk(p string, wf filepath.WalkFunc) error { return err } - fi = fs.WithName(strings.TrimPrefix(k.Name, pt.Name), fi) + fi = pkging.WithName(strings.TrimPrefix(k.Name, pt.Name), fi) err = wf(k.String(), fi, nil) if err != nil { return err diff --git a/fs/memware/walk_test.go b/pkging/memware/walk_test.go similarity index 100% rename from fs/memware/walk_test.go rename to pkging/memware/walk_test.go diff --git a/fs/memware/warehouse.go b/pkging/memware/warehouse.go similarity index 91% rename from fs/memware/warehouse.go rename to pkging/memware/warehouse.go index 6b59a52..1a66846 100644 --- a/fs/memware/warehouse.go +++ b/pkging/memware/warehouse.go @@ -6,12 +6,12 @@ import ( "os" "strings" - "github.com/markbates/pkger/fs" "github.com/markbates/pkger/here" "github.com/markbates/pkger/internal/maps" + "github.com/markbates/pkger/pkging" ) -var _ fs.Warehouse = &Warehouse{} +var _ pkging.Warehouse = &Warehouse{} func WithInfo(fx *Warehouse, infos ...here.Info) { for _, info := range infos { @@ -46,7 +46,7 @@ func (f *Warehouse) Abs(p string) (string, error) { return f.AbsPath(pt) } -func (f *Warehouse) AbsPath(pt fs.Path) (string, error) { +func (f *Warehouse) AbsPath(pt pkging.Path) (string, error) { return pt.String(), nil } @@ -63,7 +63,7 @@ func (f *Warehouse) Info(p string) (here.Info, error) { return info, nil } -func (f *Warehouse) Parse(p string) (fs.Path, error) { +func (f *Warehouse) Parse(p string) (pkging.Path, error) { return f.paths.Parse(p) } diff --git a/fs/memware/warehouse_test.go b/pkging/memware/warehouse_test.go similarity index 66% rename from fs/memware/warehouse_test.go rename to pkging/memware/warehouse_test.go index 2184752..9df9440 100644 --- a/fs/memware/warehouse_test.go +++ b/pkging/memware/warehouse_test.go @@ -3,8 +3,8 @@ package memware import ( "testing" - "github.com/markbates/pkger/fs/fstest" "github.com/markbates/pkger/here" + "github.com/markbates/pkger/pkging/waretest" "github.com/stretchr/testify/require" ) @@ -15,12 +15,12 @@ func Test_Warehouse(t *testing.T) { r.NoError(err) r.NotZero(info) - myfs, err := New(info) + mypkging, err := New(info) r.NoError(err) - WithInfo(myfs, info) + WithInfo(mypkging, info) - suite, err := fstest.NewSuite(myfs) + suite, err := waretest.NewSuite(mypkging) r.NoError(err) suite.Test(t) diff --git a/fs/mod_time.go b/pkging/mod_time.go similarity index 96% rename from fs/mod_time.go rename to pkging/mod_time.go index b715106..d81a32c 100644 --- a/fs/mod_time.go +++ b/pkging/mod_time.go @@ -1,4 +1,4 @@ -package fs +package pkging import ( "encoding/json" diff --git a/fs/osware/file.go b/pkging/osware/file.go similarity index 69% rename from fs/osware/file.go rename to pkging/osware/file.go index fba1713..cbc335e 100644 --- a/fs/osware/file.go +++ b/pkging/osware/file.go @@ -4,21 +4,21 @@ import ( "net/http" "os" - "github.com/markbates/pkger/fs" "github.com/markbates/pkger/here" + "github.com/markbates/pkger/pkging" ) -var _ fs.File = &File{} +var _ pkging.File = &File{} type File struct { *os.File - info *fs.FileInfo - her here.Info - path fs.Path - fs fs.Warehouse + info *pkging.FileInfo + her here.Info + path pkging.Path + pkging pkging.Warehouse } -func NewFile(fx fs.Warehouse, osf *os.File) (*File, error) { +func NewFile(fx pkging.Warehouse, osf *os.File) (*File, error) { pt, err := fx.Parse(osf.Name()) if err != nil { @@ -31,11 +31,11 @@ func NewFile(fx fs.Warehouse, osf *os.File) (*File, error) { } f := &File{ - File: osf, - path: pt, - fs: fx, + File: osf, + path: pt, + pkging: fx, } - f.info = fs.WithName(pt.Name, info) + f.info = pkging.WithName(pt.Name, info) her, err := here.Package(pt.Pkg) if err != nil { @@ -50,7 +50,7 @@ func (f *File) Close() error { } func (f *File) Abs() (string, error) { - return f.fs.AbsPath(f.path) + return f.pkging.AbsPath(f.path) } func (f *File) Info() here.Info { @@ -65,7 +65,7 @@ func (f *File) Open(name string) (http.File, error) { return f.File, nil } -func (f *File) Path() fs.Path { +func (f *File) Path() pkging.Path { return f.path } @@ -83,6 +83,6 @@ func (f *File) Stat() (os.FileInfo, error) { if err != nil { return nil, err } - f.info = fs.NewFileInfo(info) + f.info = pkging.NewFileInfo(info) return info, nil } diff --git a/fs/osware/warehouse.go b/pkging/osware/warehouse.go similarity index 86% rename from fs/osware/warehouse.go rename to pkging/osware/warehouse.go index b16f21a..f0e75f4 100644 --- a/fs/osware/warehouse.go +++ b/pkging/osware/warehouse.go @@ -7,12 +7,12 @@ import ( "path/filepath" "strings" - "github.com/markbates/pkger/fs" "github.com/markbates/pkger/here" "github.com/markbates/pkger/internal/maps" + "github.com/markbates/pkger/pkging" ) -var _ fs.Warehouse = &Warehouse{} +var _ pkging.Warehouse = &Warehouse{} type Warehouse struct { infos *maps.Infos @@ -28,7 +28,7 @@ func (f *Warehouse) Abs(p string) (string, error) { return f.AbsPath(pt) } -func (f *Warehouse) AbsPath(pt fs.Path) (string, error) { +func (f *Warehouse) AbsPath(pt pkging.Path) (string, error) { if pt.Pkg == f.current.ImportPath { return filepath.Join(f.current.Dir, pt.Name), nil } @@ -53,7 +53,7 @@ func New() (*Warehouse, error) { }, nil } -func (fx *Warehouse) Create(name string) (fs.File, error) { +func (fx *Warehouse) Create(name string) (pkging.File, error) { name, err := fx.Abs(name) if err != nil { return nil, err @@ -94,7 +94,7 @@ func (f *Warehouse) MkdirAll(p string, perm os.FileMode) error { return os.MkdirAll(p, perm) } -func (fx *Warehouse) Open(name string) (fs.File, error) { +func (fx *Warehouse) Open(name string) (pkging.File, error) { name, err := fx.Abs(name) if err != nil { return nil, err @@ -106,7 +106,7 @@ func (fx *Warehouse) Open(name string) (fs.File, error) { return NewFile(fx, f) } -func (f *Warehouse) Parse(p string) (fs.Path, error) { +func (f *Warehouse) Parse(p string) (pkging.Path, error) { return f.paths.Parse(p) } @@ -134,7 +134,7 @@ func (f *Warehouse) Stat(name string) (os.FileInfo, error) { return nil, err } - info = fs.WithName(pt.Name, fs.NewFileInfo(info)) + info = pkging.WithName(pt.Name, pkging.NewFileInfo(info)) return info, nil } @@ -159,7 +159,7 @@ func (f *Warehouse) Walk(p string, wf filepath.WalkFunc) error { if err != nil { return err } - return wf(pt.String(), fs.WithName(path, fs.NewFileInfo(fi)), nil) + return wf(pt.String(), pkging.WithName(path, pkging.NewFileInfo(fi)), nil) }) return err diff --git a/pkging/osware/warehouse_test.go b/pkging/osware/warehouse_test.go new file mode 100644 index 0000000..44324db --- /dev/null +++ b/pkging/osware/warehouse_test.go @@ -0,0 +1,24 @@ +package hdware + +import ( + "path/filepath" + "testing" + + "github.com/markbates/pkger/pkging/waretest" + "github.com/stretchr/testify/require" +) + +func Test_Warehouse(t *testing.T) { + r := require.New(t) + + mypkging, err := New() + r.NoError(err) + + mypkging.current.Dir = filepath.Join(mypkging.current.Dir, ".waretest") + mypkging.paths.Current = mypkging.current + + suite, err := waretest.NewSuite(mypkging) + r.NoError(err) + + suite.Test(t) +} diff --git a/fs/path.go b/pkging/path.go similarity index 97% rename from fs/path.go rename to pkging/path.go index 902c31e..f09061c 100644 --- a/fs/path.go +++ b/pkging/path.go @@ -1,4 +1,4 @@ -package fs +package pkging import ( "encoding/json" diff --git a/fs/warehouse.go b/pkging/warehouse.go similarity index 99% rename from fs/warehouse.go rename to pkging/warehouse.go index 596b8d7..63a63e9 100644 --- a/fs/warehouse.go +++ b/pkging/warehouse.go @@ -1,4 +1,4 @@ -package fs +package pkging import ( "os" diff --git a/pkging/waretest/file.go b/pkging/waretest/file.go new file mode 100644 index 0000000..9bddf94 --- /dev/null +++ b/pkging/waretest/file.go @@ -0,0 +1,12 @@ +package waretest + +import ( + "github.com/markbates/pkger/pkging" +) + +type TestFile struct { + Name string + Path pkging.Path +} + +type TestFiles map[pkging.Path]TestFile diff --git a/fs/fstest/fstest.go b/pkging/waretest/fstest.go similarity index 77% rename from fs/fstest/fstest.go rename to pkging/waretest/fstest.go index 581f6b1..1aacef7 100644 --- a/fs/fstest/fstest.go +++ b/pkging/waretest/fstest.go @@ -1,10 +1,10 @@ -package fstest +package waretest import ( - "github.com/markbates/pkger/fs" + "github.com/markbates/pkger/pkging" ) -func Files(fx fs.Warehouse) (TestFiles, error) { +func Files(fx pkging.Warehouse) (TestFiles, error) { tf := TestFiles{} for _, f := range fileList { pt, err := fx.Parse(f) diff --git a/fs/fstest/suite.go b/pkging/waretest/suite.go similarity index 85% rename from fs/fstest/suite.go rename to pkging/waretest/suite.go index 5d64d95..ce26134 100644 --- a/fs/fstest/suite.go +++ b/pkging/waretest/suite.go @@ -1,4 +1,4 @@ -package fstest +package waretest import ( "fmt" @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/markbates/pkger/fs" + "github.com/markbates/pkger/pkging" "github.com/stretchr/testify/require" ) @@ -18,12 +18,12 @@ const hart = "/easy/listening/grant.hart" const husker = "github.com/husker/du" type Suite struct { - fs.Warehouse + pkging.Warehouse } -func NewSuite(yourfs fs.Warehouse) (Suite, error) { +func NewSuite(yourpkging pkging.Warehouse) (Suite, error) { suite := Suite{ - Warehouse: yourfs, + Warehouse: yourpkging, } return suite, nil } @@ -141,17 +141,17 @@ func (s Suite) Test_Parse(t *testing.T) { ip := cur.ImportPath table := []struct { in string - exp fs.Path + exp pkging.Path }{ - {in: mould, exp: fs.Path{Pkg: ip, Name: mould}}, - {in: filepath.Join(cur.Dir, mould), exp: fs.Path{Pkg: ip, Name: mould}}, - {in: ":" + mould, exp: fs.Path{Pkg: ip, Name: mould}}, - {in: ip + ":" + mould, exp: fs.Path{Pkg: ip, Name: mould}}, - {in: ip, exp: fs.Path{Pkg: ip, Name: "/"}}, - {in: ":", exp: fs.Path{Pkg: ip, Name: "/"}}, - {in: husker + ":" + mould, exp: fs.Path{Pkg: husker, Name: mould}}, - {in: husker, exp: fs.Path{Pkg: husker, Name: "/"}}, - {in: husker + ":", exp: fs.Path{Pkg: husker, Name: "/"}}, + {in: mould, exp: pkging.Path{Pkg: ip, Name: mould}}, + {in: filepath.Join(cur.Dir, mould), exp: pkging.Path{Pkg: ip, Name: mould}}, + {in: ":" + mould, exp: pkging.Path{Pkg: ip, Name: mould}}, + {in: ip + ":" + mould, exp: pkging.Path{Pkg: ip, Name: mould}}, + {in: ip, exp: pkging.Path{Pkg: ip, Name: "/"}}, + {in: ":", exp: pkging.Path{Pkg: ip, Name: "/"}}, + {in: husker + ":" + mould, exp: pkging.Path{Pkg: husker, Name: mould}}, + {in: husker, exp: pkging.Path{Pkg: husker, Name: "/"}}, + {in: husker + ":", exp: pkging.Path{Pkg: husker, Name: "/"}}, } for _, tt := range table {