pkger/pkging/costello/create.go

46 lines
742 B
Go
Raw Normal View History

package costello
import (
2019-10-30 23:49:55 +03:00
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"github.com/markbates/pkger/pkging"
2019-10-30 23:49:55 +03:00
"github.com/stretchr/testify/require"
)
func CreateTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
2019-10-30 23:49:55 +03:00
r := require.New(t)
const name = "create.test"
fp := filepath.Join(ref.Dir, name)
os.RemoveAll(fp)
defer os.RemoveAll(fp)
_, err := os.Stat(fp)
2019-10-30 23:49:55 +03:00
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, ref, pkg)
}