something is beautiful and true

This commit is contained in:
Mark Bates 2019-09-03 12:02:55 -04:00
parent 49d408c229
commit aff26c9df7
3 changed files with 123 additions and 42 deletions

71
pkging/pkgtest/file.go Normal file
View File

@ -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")
}

View File

@ -428,45 +428,3 @@ func (s Suite) Test_HTTP_Open(t *testing.T) {
func (s Suite) Test_HTTP_Readdir(t *testing.T) { func (s Suite) Test_HTTP_Readdir(t *testing.T) {
panic("not implemented") 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))
})
}
}

52
pkging/pkgtest/util.go Normal file
View File

@ -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))
})
}
}