2019-10-26 00:11:34 +03:00
|
|
|
package costello
|
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"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/markbates/pkger/pkging"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func OpenTest(t *testing.T, pkg pkging.Pkger) {
|
2019-10-30 23:49:55 +03:00
|
|
|
openTest("go.mod", t, pkg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func openTest(name string, t *testing.T, pkg pkging.Pkger) {
|
2019-10-30 20:05:35 +03:00
|
|
|
r := require.New(t)
|
|
|
|
|
2019-10-30 23:39:05 +03:00
|
|
|
ref, err := NewRef()
|
2019-10-30 20:05:35 +03:00
|
|
|
r.NoError(err)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
osb, err := ioutil.ReadAll(osf)
|
|
|
|
r.NoError(err)
|
|
|
|
r.NoError(osf.Close())
|
|
|
|
|
2019-10-30 23:39:05 +03:00
|
|
|
r.NoError(LoadRef(ref, pkg))
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
psb, err := ioutil.ReadAll(pf)
|
|
|
|
r.NoError(err)
|
|
|
|
r.NoError(pf.Close())
|
|
|
|
|
|
|
|
r.Equal(osi.Name(), psi.Name())
|
|
|
|
r.Equal(osi.Mode(), psi.Mode())
|
|
|
|
r.Equal(osi.Size(), psi.Size())
|
|
|
|
r.Equal(osi.ModTime().Format(time.RFC3339), psi.ModTime().Format(time.RFC3339))
|
|
|
|
r.Equal(osb, psb)
|
|
|
|
}
|