forked from mirror/pkger
his suntan lotion and his castanets
This commit is contained in:
parent
da03471d96
commit
f79eafd257
|
@ -14,8 +14,9 @@ func All(t *testing.T, fn AllFn) {
|
|||
type tf func(*testing.T, pkging.Pkger)
|
||||
|
||||
tests := map[string]tf{
|
||||
"OpenTest": OpenTest,
|
||||
"StatTest": StatTest,
|
||||
"OpenTest": OpenTest,
|
||||
"StatTest": StatTest,
|
||||
"CreateTest": CreateTest,
|
||||
}
|
||||
|
||||
ref, err := NewRef()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue