2019-10-26 00:11:34 +03:00
|
|
|
package costello
|
|
|
|
|
|
|
|
import (
|
2019-10-30 23:49:55 +03:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2019-10-26 00:11:34 +03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/markbates/pkger/pkging"
|
2019-10-30 23:49:55 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-10-26 00:11:34 +03:00
|
|
|
)
|
|
|
|
|
2019-10-30 23:56:22 +03:00
|
|
|
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)
|
|
|
|
|
2019-10-30 23:56:22 +03:00
|
|
|
_, 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())
|
2019-10-30 23:56:22 +03:00
|
|
|
openTest(name, t, ref, pkg)
|
2019-10-26 00:11:34 +03:00
|
|
|
}
|