his suntan lotion and his castanets

This commit is contained in:
Mark Bates 2019-10-30 16:49:55 -04:00
parent da03471d96
commit f79eafd257
4 changed files with 69 additions and 6 deletions

View File

@ -16,6 +16,7 @@ func All(t *testing.T, fn AllFn) {
tests := map[string]tf{ tests := map[string]tf{
"OpenTest": OpenTest, "OpenTest": OpenTest,
"StatTest": StatTest, "StatTest": StatTest,
"CreateTest": CreateTest,
} }
ref, err := NewRef() ref, err := NewRef()

View File

@ -1,11 +1,48 @@
package costello package costello
import ( import (
"fmt"
"os"
"path/filepath"
"strings"
"testing" "testing"
"github.com/markbates/pkger/pkging" "github.com/markbates/pkger/pkging"
"github.com/stretchr/testify/require"
) )
func Create_Test(t *testing.T, pkg pkging.Pkger) error { func CreateTest(t *testing.T, pkg pkging.Pkger) {
return nil r := require.New(t)
ref, err := NewRef()
r.NoError(err)
const name = "create.test"
fp := filepath.Join(ref.Dir, name)
os.RemoveAll(fp)
defer os.RemoveAll(fp)
_, err = os.Stat(fp)
r.Error(err)
_, err = pkg.Stat(name)
r.Error(err)
data := []byte(strings.ToUpper(name))
osf, err := os.Create(fp)
r.NoError(err)
_, err = osf.Write(data)
r.NoError(err)
r.NoError(osf.Close())
psf, err := pkg.Create(fmt.Sprintf("/%s", name))
r.NoError(err)
_, err = psf.Write(data)
r.NoError(err)
r.NoError(psf.Close())
openTest(name, t, pkg)
} }

View File

@ -1,6 +1,7 @@
package costello package costello
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -12,12 +13,16 @@ import (
) )
func OpenTest(t *testing.T, pkg pkging.Pkger) { func OpenTest(t *testing.T, pkg pkging.Pkger) {
openTest("go.mod", t, pkg)
}
func openTest(name string, t *testing.T, pkg pkging.Pkger) {
r := require.New(t) r := require.New(t)
ref, err := NewRef() ref, err := NewRef()
r.NoError(err) r.NoError(err)
osf, err := os.Open(filepath.Join(ref.Dir, "go.mod")) osf, err := os.Open(filepath.Join(ref.Dir, name))
r.NoError(err) r.NoError(err)
osi, err := osf.Stat() osi, err := osf.Stat()
@ -29,7 +34,7 @@ func OpenTest(t *testing.T, pkg pkging.Pkger) {
r.NoError(LoadRef(ref, pkg)) r.NoError(LoadRef(ref, pkg))
pf, err := pkg.Open("/go.mod") pf, err := pkg.Open(fmt.Sprintf("/%s", name))
r.NoError(err) r.NoError(err)
psi, err := pf.Stat() psi, err := pf.Stat()

20
pkging/mem/create_test.go Normal file
View File

@ -0,0 +1,20 @@
package mem
import (
"testing"
"github.com/markbates/pkger/pkging/costello"
"github.com/stretchr/testify/require"
)
func Test_Pkger_Create(t *testing.T) {
r := require.New(t)
ref, err := costello.NewRef()
r.NoError(err)
pkg, err := New(ref.Info)
r.NoError(err)
costello.CreateTest(t, pkg)
}