pkger/pkging/pkgtest/create.go

43 lines
650 B
Go
Raw Permalink Normal View History

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