pkger/pkging/costello/costello.go

84 lines
1.4 KiB
Go
Raw Normal View History

package costello
import (
2019-10-31 00:15:49 +03:00
"fmt"
2019-10-31 00:32:47 +03:00
"os"
2019-10-30 23:39:05 +03:00
"testing"
"github.com/markbates/pkger/here"
"github.com/markbates/pkger/pkging"
2019-10-30 23:39:05 +03:00
"github.com/stretchr/testify/require"
)
2019-10-30 23:39:05 +03:00
type AllFn func(ref *Ref) (pkging.Pkger, error)
func All(t *testing.T, fn AllFn) {
2019-10-30 23:39:05 +03:00
r := require.New(t)
type tf func(*testing.T, *Ref, pkging.Pkger)
2019-10-30 23:39:05 +03:00
tests := map[string]tf{
2019-10-31 00:32:47 +03:00
"Open": OpenTest,
"Stat": StatTest,
"Create": CreateTest,
"Current": CurrentTest,
"Info": InfoTest,
"MkdirAll": MkdirAllTest,
"Remove": RemoveTest,
"RemoveAll": RemoveAllTest,
"Walk": WalkTest,
2019-10-30 23:39:05 +03:00
}
ref, err := NewRef()
r.NoError(err)
2019-10-31 00:15:49 +03:00
pkg, err := fn(ref)
r.NoError(err)
2019-10-30 23:39:05 +03:00
for n, tt := range tests {
2019-10-31 00:15:49 +03:00
t.Run(fmt.Sprintf("%T/%s", pkg, n), func(st *testing.T) {
st.Parallel()
ref, err := NewRef()
r.NoError(err)
2019-10-30 23:39:05 +03:00
pkg, err := fn(ref)
r.NoError(err)
tt(st, ref, pkg)
2019-10-30 23:39:05 +03:00
})
}
}
2019-10-31 00:32:47 +03:00
func cmpFileInfo(t *testing.T, a os.FileInfo, b os.FileInfo) {
t.Helper()
2019-10-31 00:32:47 +03:00
r := require.New(t)
2019-10-31 00:32:47 +03:00
r.Equal(a.IsDir(), b.IsDir())
r.Equal(a.Mode().String(), b.Mode().String())
2019-10-31 00:32:47 +03:00
r.Equal(a.Name(), b.Name())
r.Equal(a.Size(), b.Size())
r.NotZero(b.ModTime())
}
func cmpHereInfo(t *testing.T, a here.Info, b here.Info) {
t.Helper()
r := require.New(t)
r.NotZero(a)
r.NotZero(b)
r.Equal(a.ImportPath, b.ImportPath)
r.Equal(a.Name, b.Name)
am := a.Module
bm := b.Module
r.Equal(am.Path, bm.Path)
r.Equal(am.Main, bm.Main)
r.Equal(am.GoVersion, bm.GoVersion)
2019-10-31 00:32:47 +03:00
}