diff --git a/pkging/pkgtest/file.go b/pkging/pkgtest/file.go new file mode 100644 index 0000000..ca537a6 --- /dev/null +++ b/pkging/pkgtest/file.go @@ -0,0 +1,71 @@ +package pkgtest + +import ( + "path/filepath" + "testing" + + "github.com/markbates/pkger/pkging/pkgutil" + "github.com/stretchr/testify/require" +) + +func (s Suite) Test_File_Info(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}, + } + + for _, tt := range table { + t.Run(tt.in, func(st *testing.T) { + r := require.New(st) + + r.NoError(s.RemoveAll(mould)) + r.NoError(s.MkdirAll(filepath.Dir(tt.in), 0755)) + err := pkgutil.WriteFile(s, tt.in, []byte(mould), 0644) + r.NoError(err) + + f, err := s.Open(tt.in) + r.NoError(err) + r.Equal(cur.ImportPath, f.Info().ImportPath) + }) + } +} + +func (s Suite) Test_File_Name(t *testing.T) { + panic("not implemented") +} + +func (s Suite) Test_File_Open(t *testing.T) { + panic("not implemented") +} + +func (s Suite) Test_File_Path(t *testing.T) { + panic("not implemented") +} + +func (s Suite) Test_File_Read(t *testing.T) { + panic("not implemented") +} + +func (s Suite) Test_File_Readdir(t *testing.T) { + panic("not implemented") +} + +func (s Suite) Test_File_Seek(t *testing.T) { + panic("not implemented") +} + +func (s Suite) Test_File_Stat(t *testing.T) { + panic("not implemented") +} + +func (s Suite) Test_File_Write(t *testing.T) { + panic("not implemented") +} diff --git a/pkging/pkgtest/suite.go b/pkging/pkgtest/suite.go index 7fbdc40..13b9e34 100644 --- a/pkging/pkgtest/suite.go +++ b/pkging/pkgtest/suite.go @@ -428,45 +428,3 @@ func (s Suite) Test_HTTP_Open(t *testing.T) { func (s Suite) Test_HTTP_Readdir(t *testing.T) { panic("not implemented") } - -func (s Suite) Test_ReadFile(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: hart}, - } - - 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())) - r.NoError(s.MkdirAll(filepath.Dir(pt.Name), 0755)) - - f, err := s.Create(tt.in) - r.NoError(err) - - body := "!" + pt.String() - _, err = io.Copy(f, strings.NewReader(body)) - r.NoError(err) - r.NoError(f.Close()) - - b, err := pkgutil.ReadFile(s, tt.in) - r.NoError(err) - r.Equal(body, string(b)) - }) - } -} diff --git a/pkging/pkgtest/util.go b/pkging/pkgtest/util.go new file mode 100644 index 0000000..7c7689f --- /dev/null +++ b/pkging/pkgtest/util.go @@ -0,0 +1,52 @@ +package pkgtest + +import ( + "io" + "path/filepath" + "strings" + "testing" + + "github.com/markbates/pkger/pkging/pkgutil" + "github.com/stretchr/testify/require" +) + +func (s Suite) Test_Util_ReadFile(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: hart}, + } + + 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())) + r.NoError(s.MkdirAll(filepath.Dir(pt.Name), 0755)) + + f, err := s.Create(tt.in) + r.NoError(err) + + body := "!" + pt.String() + _, err = io.Copy(f, strings.NewReader(body)) + r.NoError(err) + r.NoError(f.Close()) + + b, err := pkgutil.ReadFile(s, tt.in) + r.NoError(err) + r.Equal(body, string(b)) + }) + } +}