2019-10-26 00:11:34 +03:00
|
|
|
package costello
|
|
|
|
|
|
|
|
import (
|
2019-10-31 18:06:20 +03:00
|
|
|
"io/ioutil"
|
2019-10-30 23:49:55 +03:00
|
|
|
"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)
|
|
|
|
|
2019-10-31 18:06:20 +03:00
|
|
|
const name = "/create.test"
|
2019-10-30 23:49:55 +03:00
|
|
|
|
2019-10-31 18:06:20 +03:00
|
|
|
_, err := pkg.Stat(name)
|
2019-10-30 23:49:55 +03:00
|
|
|
r.Error(err)
|
|
|
|
|
|
|
|
data := []byte(strings.ToUpper(name))
|
|
|
|
|
2019-10-31 18:06:20 +03:00
|
|
|
f, err := pkg.Create(name)
|
2019-10-30 23:49:55 +03:00
|
|
|
r.NoError(err)
|
|
|
|
|
2019-10-31 18:06:20 +03:00
|
|
|
_, err = f.Write(data)
|
2019-10-30 23:49:55 +03:00
|
|
|
r.NoError(err)
|
2019-10-31 18:06:20 +03:00
|
|
|
r.NoError(f.Close())
|
2019-10-30 23:49:55 +03:00
|
|
|
|
2019-10-31 18:06:20 +03:00
|
|
|
f, err = pkg.Open(name)
|
2019-10-30 23:49:55 +03:00
|
|
|
r.NoError(err)
|
|
|
|
|
2019-10-31 18:06:20 +03:00
|
|
|
info, err := f.Stat()
|
2019-10-30 23:49:55 +03:00
|
|
|
r.NoError(err)
|
2019-10-31 18:06:20 +03:00
|
|
|
|
|
|
|
b, err := ioutil.ReadAll(f)
|
|
|
|
r.NoError(err)
|
|
|
|
r.NoError(f.Close())
|
|
|
|
|
|
|
|
r.Equal(data, b)
|
|
|
|
r.Equal("create.test", info.Name())
|
|
|
|
|
2019-10-26 00:11:34 +03:00
|
|
|
}
|