2019-11-01 23:08:10 +03:00
|
|
|
package pkgtest
|
2019-10-30 20:05:35 +03:00
|
|
|
|
|
|
|
import (
|
2019-10-30 23:49:55 +03:00
|
|
|
"fmt"
|
2019-10-30 20:05:35 +03:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/markbates/pkger/pkging"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2019-10-30 23:56:22 +03:00
|
|
|
func OpenTest(t *testing.T, ref *Ref, pkg pkging.Pkger) {
|
2019-10-30 20:05:35 +03:00
|
|
|
r := require.New(t)
|
|
|
|
|
2019-11-01 00:20:15 +03:00
|
|
|
name := "/go.mod"
|
|
|
|
|
2019-10-30 23:49:55 +03:00
|
|
|
osf, err := os.Open(filepath.Join(ref.Dir, name))
|
2019-10-30 20:05:35 +03:00
|
|
|
r.NoError(err)
|
|
|
|
|
|
|
|
osi, err := osf.Stat()
|
|
|
|
r.NoError(err)
|
|
|
|
|
2019-11-01 22:53:54 +03:00
|
|
|
_, err = LoadFile(name, ref, pkg)
|
2019-11-01 00:20:15 +03:00
|
|
|
r.NoError(err)
|
2019-10-30 23:39:05 +03:00
|
|
|
|
2019-10-30 23:49:55 +03:00
|
|
|
pf, err := pkg.Open(fmt.Sprintf("/%s", name))
|
2019-10-30 20:05:35 +03:00
|
|
|
r.NoError(err)
|
|
|
|
|
|
|
|
psi, err := pf.Stat()
|
|
|
|
r.NoError(err)
|
|
|
|
|
2019-11-01 22:53:54 +03:00
|
|
|
CmpFileInfo(t, osi, psi)
|
2019-10-31 00:15:49 +03:00
|
|
|
|
|
|
|
osb, err := ioutil.ReadAll(osf)
|
|
|
|
r.NoError(err)
|
|
|
|
r.NoError(osf.Close())
|
|
|
|
|
|
|
|
psb, err := ioutil.ReadAll(pf)
|
|
|
|
r.NoError(err)
|
|
|
|
r.NoError(pf.Close())
|
|
|
|
|
2019-10-30 20:05:35 +03:00
|
|
|
r.Equal(osb, psb)
|
|
|
|
}
|