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{
"OpenTest": OpenTest,
"StatTest": StatTest,
"CreateTest": CreateTest,
}
ref, err := NewRef()

View File

@ -1,11 +1,48 @@
package costello
import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"github.com/markbates/pkger/pkging"
"github.com/stretchr/testify/require"
)
func Create_Test(t *testing.T, pkg pkging.Pkger) error {
return nil
func CreateTest(t *testing.T, pkg pkging.Pkger) {
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
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -12,12 +13,16 @@ import (
)
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)
ref, err := NewRef()
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)
osi, err := osf.Stat()
@ -29,7 +34,7 @@ func OpenTest(t *testing.T, pkg pkging.Pkger) {
r.NoError(LoadRef(ref, pkg))
pf, err := pkg.Open("/go.mod")
pf, err := pkg.Open(fmt.Sprintf("/%s", name))
r.NoError(err)
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)
}