Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
blame it on ray
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Sep 1, 2019
1 parent 9666017 commit 926eafe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.fstest
*.log
.DS_Store
doc
Expand Down
13 changes: 1 addition & 12 deletions fs/fstest/fstest.go
@@ -1,15 +1,13 @@
package fstest

import (
"path"

"github.com/markbates/pkger/fs"
)

func Files(fx fs.FileSystem) (TestFiles, error) {
tf := TestFiles{}
for _, f := range fileList {
pt, err := Path(fx, f)
pt, err := fx.Parse(f)
if err != nil {
return tf, err
}
Expand All @@ -22,15 +20,6 @@ func Files(fx fs.FileSystem) (TestFiles, error) {
return tf, nil
}

func Path(fx fs.FileSystem, p string) (fs.Path, error) {
pt, err := fx.Parse(p)
if err != nil {
return pt, err
}
pt.Name = path.Join("/.fstest", pt.Name)
return pt, nil
}

var fileList = []string{
"/main.go",
"/go.mod",
Expand Down
26 changes: 14 additions & 12 deletions fs/fstest/suite.go
Expand Up @@ -3,6 +3,7 @@ package fstest
import (
"fmt"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -63,25 +64,26 @@ func (s *FileSystem) sub(t *testing.T, m reflect.Method) {
}

func (s *FileSystem) Clean() error {
pt, err := Path(s, "/")
pt, err := s.Parse("/")
if err != nil {
return err
}

if err := s.RemoveAll(pt.Name); err != nil {
return err
}

if _, err := s.Stat(pt.Name); err == nil {
return fmt.Errorf("expected %q to be, you know, not there any more", pt)
}
_ = pt
// if err := s.RemoveAll(pt.Name); err != nil {
// return err
// }
//
// if _, err := s.Stat(pt.Name); err == nil {
// return fmt.Errorf("expected %q to be, you know, not there any more", pt)
// }
return nil
}

func (s *FileSystem) Test_Create(t *testing.T) {
r := require.New(t)

pt, err := Path(s, "i/want/candy.song")
pt, err := s.Parse("/i/want/candy.song")
r.NoError(err)

f, err := s.Create(pt.Name)
Expand All @@ -94,6 +96,7 @@ func (s *FileSystem) Test_Create(t *testing.T) {
r.Equal(pt.Name, fi.Name())
r.Equal(os.FileMode(0644), fi.Mode())
r.NotZero(fi.ModTime())
r.NoError(s.RemoveAll(pt.String()))
}

func (s *FileSystem) Test_Current(t *testing.T) {
Expand Down Expand Up @@ -136,6 +139,7 @@ func (s *FileSystem) Test_Parse(t *testing.T) {
exp fs.Path
}{
{in: "/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: filepath.Join(cur.Dir, "foo.go"), exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: ip + ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}},
{in: ip, exp: fs.Path{Pkg: ip, Name: "/"}},
Expand Down Expand Up @@ -188,9 +192,7 @@ func (s *FileSystem) Test_Stat(t *testing.T) {
return
}

pt, err := Path(s, tt.in)
fmt.Println(">>>TODO fs/fstest/suite.go:189: tt.in ", tt.in)
fmt.Println(">>>TODO fs/fstest/suite.go:189: pt ", pt)
pt, err := s.Parse(tt.in)
r.NoError(err)

// r.Fail(pt.String())
Expand Down
7 changes: 6 additions & 1 deletion fs/hdfs/hdfs.go
Expand Up @@ -134,7 +134,12 @@ func (f *FS) Walk(p string, wf filepath.WalkFunc) error {
}

func (f *FS) locate(p string) (string, error) {
return f.current.FilePath(p), nil
pt, err := f.Parse(p)
if err != nil {
return p, err
}
p = f.current.FilePath(pt.Name)
return p, nil
}

func (fx *FS) Remove(name string) error {
Expand Down
1 change: 1 addition & 0 deletions internal/maps/paths.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 926eafe

Please sign in to comment.