forked from mirror/pkger
dancing in the dark
This commit is contained in:
parent
c3ae1d1bda
commit
b6440c5fec
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// no such file or directory
|
// no such file or directory
|
||||||
func (fx *Warehouse) Create(name string) (pkging.File, error) {
|
func (fx *Pkger) Create(name string) (pkging.File, error) {
|
||||||
pt, err := fx.Parse(name)
|
pt, err := fx.Parse(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
// func Test_Create(t *testing.T) {
|
// func Test_Create(t *testing.T) {
|
||||||
// r := require.New(t)
|
// r := require.New(t)
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -27,7 +27,7 @@ type File struct {
|
||||||
parent pkging.Path
|
parent pkging.Path
|
||||||
writer *bytes.Buffer
|
writer *bytes.Buffer
|
||||||
reader io.Reader
|
reader io.Reader
|
||||||
pkging pkging.Warehouse
|
pkging pkging.Pkger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *File) Seek(ofpkginget int64, whence int) (int64, error) {
|
func (f *File) Seek(ofpkginget int64, whence int) (int64, error) {
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
// func Test_File_Read_Memory(t *testing.T) {
|
// func Test_File_Read_Memory(t *testing.T) {
|
||||||
// r := require.New(t)
|
// r := require.New(t)
|
|
@ -0,0 +1 @@
|
||||||
|
package mem
|
|
@ -1,9 +1,9 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
// func Test_HTTP_Dir(t *testing.T) {
|
// func Test_HTTP_Dir(t *testing.T) {
|
||||||
// r := require.New(t)
|
// r := require.New(t)
|
||||||
//
|
//
|
||||||
// fs := NewWarehouse()
|
// fs := NewPkger()
|
||||||
//
|
//
|
||||||
// r.NoError(Folder.Create(fs))
|
// r.NoError(Folder.Create(fs))
|
||||||
//
|
//
|
||||||
|
@ -24,7 +24,7 @@ package memware
|
||||||
// func Test_HTTP_File_Memory(t *testing.T) {
|
// func Test_HTTP_File_Memory(t *testing.T) {
|
||||||
// r := require.New(t)
|
// r := require.New(t)
|
||||||
//
|
//
|
||||||
// fs := NewWarehouse()
|
// fs := NewPkger()
|
||||||
// r.NoError(Folder.Create(fs))
|
// r.NoError(Folder.Create(fs))
|
||||||
//
|
//
|
||||||
// dir, err := fs.Open("/")
|
// dir, err := fs.Open("/")
|
||||||
|
@ -44,7 +44,7 @@ package memware
|
||||||
// func Test_HTTP_Dir_Memory_StripPrefix(t *testing.T) {
|
// func Test_HTTP_Dir_Memory_StripPrefix(t *testing.T) {
|
||||||
// r := require.New(t)
|
// r := require.New(t)
|
||||||
//
|
//
|
||||||
// fs := NewWarehouse()
|
// fs := NewPkger()
|
||||||
// r.NoError(Folder.Create(fs))
|
// r.NoError(Folder.Create(fs))
|
||||||
//
|
//
|
||||||
// dir, err := fs.Open("/public")
|
// dir, err := fs.Open("/public")
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
// func Test_File_JSON(t *testing.T) {
|
// func Test_File_JSON(t *testing.T) {
|
||||||
// r := require.New(t)
|
// r := require.New(t)
|
|
@ -1,8 +1,7 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -11,16 +10,16 @@ import (
|
||||||
"github.com/markbates/pkger/pkging"
|
"github.com/markbates/pkger/pkging"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ pkging.Warehouse = &Warehouse{}
|
var _ pkging.Pkger = &Pkger{}
|
||||||
|
|
||||||
func WithInfo(fx *Warehouse, infos ...here.Info) {
|
func WithInfo(fx *Pkger, infos ...here.Info) {
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
fx.infos.Store(info.ImportPath, info)
|
fx.infos.Store(info.ImportPath, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(info here.Info) (*Warehouse, error) {
|
func New(info here.Info) (*Pkger, error) {
|
||||||
f := &Warehouse{
|
f := &Pkger{
|
||||||
infos: &maps.Infos{},
|
infos: &maps.Infos{},
|
||||||
paths: &maps.Paths{
|
paths: &maps.Paths{
|
||||||
Current: info,
|
Current: info,
|
||||||
|
@ -31,14 +30,14 @@ func New(info here.Info) (*Warehouse, error) {
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Warehouse struct {
|
type Pkger struct {
|
||||||
infos *maps.Infos
|
infos *maps.Infos
|
||||||
paths *maps.Paths
|
paths *maps.Paths
|
||||||
files *maps.Files
|
files *maps.Files
|
||||||
current here.Info
|
current here.Info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Abs(p string) (string, error) {
|
func (f *Pkger) Abs(p string) (string, error) {
|
||||||
pt, err := f.Parse(p)
|
pt, err := f.Parse(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -46,15 +45,15 @@ func (f *Warehouse) Abs(p string) (string, error) {
|
||||||
return f.AbsPath(pt)
|
return f.AbsPath(pt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) AbsPath(pt pkging.Path) (string, error) {
|
func (f *Pkger) AbsPath(pt pkging.Path) (string, error) {
|
||||||
return pt.String(), nil
|
return pt.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Current() (here.Info, error) {
|
func (f *Pkger) Current() (here.Info, error) {
|
||||||
return f.current, nil
|
return f.current, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Info(p string) (here.Info, error) {
|
func (f *Pkger) Info(p string) (here.Info, error) {
|
||||||
info, ok := f.infos.Load(p)
|
info, ok := f.infos.Load(p)
|
||||||
if !ok {
|
if !ok {
|
||||||
return info, fmt.Errorf("no such package %q", p)
|
return info, fmt.Errorf("no such package %q", p)
|
||||||
|
@ -63,20 +62,11 @@ func (f *Warehouse) Info(p string) (here.Info, error) {
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Parse(p string) (pkging.Path, error) {
|
func (f *Pkger) Parse(p string) (pkging.Path, error) {
|
||||||
return f.paths.Parse(p)
|
return f.paths.Parse(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fx *Warehouse) ReadFile(s string) ([]byte, error) {
|
func (fx *Pkger) Remove(name string) error {
|
||||||
f, err := fx.Open(s)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
return ioutil.ReadAll(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fx *Warehouse) Remove(name string) error {
|
|
||||||
pt, err := fx.Parse(name)
|
pt, err := fx.Parse(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -90,7 +80,7 @@ func (fx *Warehouse) Remove(name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fx *Warehouse) RemoveAll(name string) error {
|
func (fx *Pkger) RemoveAll(name string) error {
|
||||||
pt, err := fx.Parse(name)
|
pt, err := fx.Parse(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
|
@ -1,14 +1,14 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/markbates/pkger/here"
|
"github.com/markbates/pkger/here"
|
||||||
"github.com/markbates/pkger/pkging/waretest"
|
"github.com/markbates/pkger/pkging/pkgtest"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_Warehouse(t *testing.T) {
|
func Test_Pkger(t *testing.T) {
|
||||||
r := require.New(t)
|
r := require.New(t)
|
||||||
|
|
||||||
info, err := here.Current()
|
info, err := here.Current()
|
||||||
|
@ -20,7 +20,7 @@ func Test_Warehouse(t *testing.T) {
|
||||||
|
|
||||||
WithInfo(wh, info)
|
WithInfo(wh, info)
|
||||||
|
|
||||||
suite, err := waretest.NewSuite(wh)
|
suite, err := pkgtest.NewSuite(wh)
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
|
|
||||||
suite.Test(t)
|
suite.Test(t)
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/markbates/pkger/pkging"
|
"github.com/markbates/pkger/pkging"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (fx *Warehouse) MkdirAll(p string, perm os.FileMode) error {
|
func (fx *Pkger) MkdirAll(p string, perm os.FileMode) error {
|
||||||
path, err := fx.Parse(p)
|
path, err := fx.Parse(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/markbates/pkger/pkging"
|
"github.com/markbates/pkger/pkging"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (fx *Warehouse) Open(name string) (pkging.File, error) {
|
func (fx *Pkger) Open(name string) (pkging.File, error) {
|
||||||
pt, err := fx.Parse(name)
|
pt, err := fx.Parse(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
// func Test_Open(t *testing.T) {
|
// func Test_Open(t *testing.T) {
|
||||||
// r := require.New(t)
|
// r := require.New(t)
|
|
@ -1,11 +1,11 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (fx *Warehouse) Stat(name string) (os.FileInfo, error) {
|
func (fx *Pkger) Stat(name string) (os.FileInfo, error) {
|
||||||
pt, err := fx.Parse(name)
|
pt, err := fx.Parse(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
// func Test_Stat(t *testing.T) {
|
// func Test_Stat(t *testing.T) {
|
||||||
// r := require.New(t)
|
// r := require.New(t)
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/markbates/pkger/pkging"
|
"github.com/markbates/pkger/pkging"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *Warehouse) Walk(p string, wf filepath.WalkFunc) error {
|
func (f *Pkger) Walk(p string, wf filepath.WalkFunc) error {
|
||||||
keys := f.files.Keys()
|
keys := f.files.Keys()
|
||||||
|
|
||||||
pt, err := f.Parse(p)
|
pt, err := f.Parse(p)
|
|
@ -1,4 +1,4 @@
|
||||||
package memware
|
package mem
|
||||||
|
|
||||||
// func Test_Walk(t *testing.T) {
|
// func Test_Walk(t *testing.T) {
|
||||||
// r := require.New(t)
|
// r := require.New(t)
|
|
@ -1 +0,0 @@
|
||||||
package memware
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/markbates/pkger/here"
|
"github.com/markbates/pkger/here"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Warehouse interface {
|
type Pkger interface {
|
||||||
Parse(p string) (Path, error)
|
Parse(p string) (Path, error)
|
||||||
Abs(string) (string, error)
|
Abs(string) (string, error)
|
||||||
AbsPath(Path) (string, error)
|
AbsPath(Path) (string, error)
|
||||||
|
@ -15,9 +15,6 @@ type Warehouse interface {
|
||||||
Current() (here.Info, error)
|
Current() (here.Info, error)
|
||||||
Info(p string) (here.Info, error)
|
Info(p string) (here.Info, error)
|
||||||
|
|
||||||
// ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.
|
|
||||||
ReadFile(s string) ([]byte, error)
|
|
||||||
|
|
||||||
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
|
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
|
||||||
Create(name string) (File, error)
|
Create(name string) (File, error)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package waretest
|
package pkgtest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -11,6 +11,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/markbates/pkger/pkging"
|
"github.com/markbates/pkger/pkging"
|
||||||
|
"github.com/markbates/pkger/pkging/pkgutil"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,12 +20,12 @@ const hart = "/easy/listening/grant.hart"
|
||||||
const husker = "github.com/husker/du"
|
const husker = "github.com/husker/du"
|
||||||
|
|
||||||
type Suite struct {
|
type Suite struct {
|
||||||
pkging.Warehouse
|
pkging.Pkger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSuite(yourpkging pkging.Warehouse) (Suite, error) {
|
func NewSuite(yourpkging pkging.Pkger) (Suite, error) {
|
||||||
suite := Suite{
|
suite := Suite{
|
||||||
Warehouse: yourpkging,
|
Pkger: yourpkging,
|
||||||
}
|
}
|
||||||
return suite, nil
|
return suite, nil
|
||||||
}
|
}
|
||||||
|
@ -46,7 +47,7 @@ func (s Suite) Test(t *testing.T) {
|
||||||
|
|
||||||
func (s Suite) sub(t *testing.T, m reflect.Method) {
|
func (s Suite) sub(t *testing.T, m reflect.Method) {
|
||||||
name := strings.TrimPrefix(m.Name, "Test_")
|
name := strings.TrimPrefix(m.Name, "Test_")
|
||||||
name = fmt.Sprintf("%T_%s", s.Warehouse, name)
|
name = fmt.Sprintf("%T_%s", s.Pkger, name)
|
||||||
t.Run(name, func(st *testing.T) {
|
t.Run(name, func(st *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
|
@ -417,6 +418,18 @@ func (s Suite) Test_Walk(t *testing.T) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s Suite) Test_Remove(t *testing.T) {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Suite) Test_HTTP_Open(t *testing.T) {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Suite) Test_HTTP_Readdir(t *testing.T) {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func (s Suite) Test_ReadFile(t *testing.T) {
|
func (s Suite) Test_ReadFile(t *testing.T) {
|
||||||
r := require.New(t)
|
r := require.New(t)
|
||||||
|
|
||||||
|
@ -452,7 +465,7 @@ func (s Suite) Test_ReadFile(t *testing.T) {
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
r.NoError(f.Close())
|
r.NoError(f.Close())
|
||||||
|
|
||||||
b, err := s.ReadFile(tt.in)
|
b, err := pkgutil.ReadFile(s, tt.in)
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
r.Equal(body, string(b))
|
r.Equal(body, string(b))
|
||||||
})
|
})
|
|
@ -0,0 +1,17 @@
|
||||||
|
package pkgutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/markbates/pkger/pkging"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.
|
||||||
|
func ReadFile(pkg pkging.Pkger, s string) ([]byte, error) {
|
||||||
|
f, err := pkg.Open(s)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
return ioutil.ReadAll(f)
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package hdware
|
package stdos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -15,10 +15,10 @@ type File struct {
|
||||||
info *pkging.FileInfo
|
info *pkging.FileInfo
|
||||||
her here.Info
|
her here.Info
|
||||||
path pkging.Path
|
path pkging.Path
|
||||||
pkging pkging.Warehouse
|
pkging pkging.Pkger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFile(fx pkging.Warehouse, osf *os.File) (*File, error) {
|
func NewFile(fx pkging.Pkger, osf *os.File) (*File, error) {
|
||||||
|
|
||||||
pt, err := fx.Parse(osf.Name())
|
pt, err := fx.Parse(osf.Name())
|
||||||
if err != nil {
|
if err != nil {
|
|
@ -1,4 +1,4 @@
|
||||||
package hdware
|
package stdos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -12,15 +12,15 @@ import (
|
||||||
"github.com/markbates/pkger/pkging"
|
"github.com/markbates/pkger/pkging"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ pkging.Warehouse = &Warehouse{}
|
var _ pkging.Pkger = &Pkger{}
|
||||||
|
|
||||||
type Warehouse struct {
|
type Pkger struct {
|
||||||
infos *maps.Infos
|
infos *maps.Infos
|
||||||
paths *maps.Paths
|
paths *maps.Paths
|
||||||
current here.Info
|
current here.Info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Abs(p string) (string, error) {
|
func (f *Pkger) Abs(p string) (string, error) {
|
||||||
pt, err := f.Parse(p)
|
pt, err := f.Parse(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -28,7 +28,7 @@ func (f *Warehouse) Abs(p string) (string, error) {
|
||||||
return f.AbsPath(pt)
|
return f.AbsPath(pt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) AbsPath(pt pkging.Path) (string, error) {
|
func (f *Pkger) AbsPath(pt pkging.Path) (string, error) {
|
||||||
if pt.Pkg == f.current.ImportPath {
|
if pt.Pkg == f.current.ImportPath {
|
||||||
return filepath.Join(f.current.Dir, pt.Name), nil
|
return filepath.Join(f.current.Dir, pt.Name), nil
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,12 @@ func (f *Warehouse) AbsPath(pt pkging.Path) (string, error) {
|
||||||
return filepath.Join(info.Dir, pt.Name), nil
|
return filepath.Join(info.Dir, pt.Name), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() (*Warehouse, error) {
|
func New() (*Pkger, error) {
|
||||||
info, err := here.Current()
|
info, err := here.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Warehouse{
|
return &Pkger{
|
||||||
infos: &maps.Infos{},
|
infos: &maps.Infos{},
|
||||||
paths: &maps.Paths{
|
paths: &maps.Paths{
|
||||||
Current: info,
|
Current: info,
|
||||||
|
@ -53,7 +53,7 @@ func New() (*Warehouse, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fx *Warehouse) Create(name string) (pkging.File, error) {
|
func (fx *Pkger) Create(name string) (pkging.File, error) {
|
||||||
name, err := fx.Abs(name)
|
name, err := fx.Abs(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -65,11 +65,11 @@ func (fx *Warehouse) Create(name string) (pkging.File, error) {
|
||||||
return NewFile(fx, f)
|
return NewFile(fx, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Current() (here.Info, error) {
|
func (f *Pkger) Current() (here.Info, error) {
|
||||||
return f.current, nil
|
return f.current, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Info(p string) (here.Info, error) {
|
func (f *Pkger) Info(p string) (here.Info, error) {
|
||||||
info, ok := f.infos.Load(p)
|
info, ok := f.infos.Load(p)
|
||||||
if ok {
|
if ok {
|
||||||
return info, nil
|
return info, nil
|
||||||
|
@ -83,7 +83,7 @@ func (f *Warehouse) Info(p string) (here.Info, error) {
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) MkdirAll(p string, perm os.FileMode) error {
|
func (f *Pkger) MkdirAll(p string, perm os.FileMode) error {
|
||||||
p, err := f.Abs(p)
|
p, err := f.Abs(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -91,7 +91,7 @@ func (f *Warehouse) MkdirAll(p string, perm os.FileMode) error {
|
||||||
return os.MkdirAll(p, perm)
|
return os.MkdirAll(p, perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fx *Warehouse) Open(name string) (pkging.File, error) {
|
func (fx *Pkger) Open(name string) (pkging.File, error) {
|
||||||
name, err := fx.Abs(name)
|
name, err := fx.Abs(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -103,11 +103,11 @@ func (fx *Warehouse) Open(name string) (pkging.File, error) {
|
||||||
return NewFile(fx, f)
|
return NewFile(fx, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Parse(p string) (pkging.Path, error) {
|
func (f *Pkger) Parse(p string) (pkging.Path, error) {
|
||||||
return f.paths.Parse(p)
|
return f.paths.Parse(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) ReadFile(s string) ([]byte, error) {
|
func (f *Pkger) ReadFile(s string) ([]byte, error) {
|
||||||
s, err := f.Abs(s)
|
s, err := f.Abs(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -115,7 +115,7 @@ func (f *Warehouse) ReadFile(s string) ([]byte, error) {
|
||||||
return ioutil.ReadFile(s)
|
return ioutil.ReadFile(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Stat(name string) (os.FileInfo, error) {
|
func (f *Pkger) Stat(name string) (os.FileInfo, error) {
|
||||||
pt, err := f.Parse(name)
|
pt, err := f.Parse(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -136,7 +136,7 @@ func (f *Warehouse) Stat(name string) (os.FileInfo, error) {
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Warehouse) Walk(p string, wf filepath.WalkFunc) error {
|
func (f *Pkger) Walk(p string, wf filepath.WalkFunc) error {
|
||||||
fp, err := f.Abs(p)
|
fp, err := f.Abs(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -162,7 +162,7 @@ func (f *Warehouse) Walk(p string, wf filepath.WalkFunc) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fx *Warehouse) Remove(name string) error {
|
func (fx *Pkger) Remove(name string) error {
|
||||||
name, err := fx.Abs(name)
|
name, err := fx.Abs(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -170,7 +170,7 @@ func (fx *Warehouse) Remove(name string) error {
|
||||||
return os.Remove(name)
|
return os.Remove(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fx *Warehouse) RemoveAll(name string) error {
|
func (fx *Pkger) RemoveAll(name string) error {
|
||||||
name, err := fx.Abs(name)
|
name, err := fx.Abs(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
|
@ -1,23 +1,23 @@
|
||||||
package hdware
|
package stdos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/markbates/pkger/pkging/waretest"
|
"github.com/markbates/pkger/pkging/pkgtest"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_Warehouse(t *testing.T) {
|
func Test_Pkger(t *testing.T) {
|
||||||
r := require.New(t)
|
r := require.New(t)
|
||||||
|
|
||||||
mypkging, err := New()
|
mypkging, err := New()
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
|
|
||||||
mypkging.current.Dir = filepath.Join(mypkging.current.Dir, ".waretest")
|
mypkging.current.Dir = filepath.Join(mypkging.current.Dir, ".pkgtest")
|
||||||
mypkging.paths.Current = mypkging.current
|
mypkging.paths.Current = mypkging.current
|
||||||
|
|
||||||
suite, err := waretest.NewSuite(mypkging)
|
suite, err := pkgtest.NewSuite(mypkging)
|
||||||
r.NoError(err)
|
r.NoError(err)
|
||||||
|
|
||||||
suite.Test(t)
|
suite.Test(t)
|
|
@ -1 +0,0 @@
|
||||||
package waretest
|
|
Loading…
Reference in New Issue