pkger/pkging/costello/costello.go

56 lines
1.1 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"
2019-10-31 00:32:47 +03:00
"time"
"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, ref *Ref, 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
}
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()
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()
r := require.New(t)
r.Equal(a.IsDir(), b.IsDir())
r.Equal(a.ModTime().Format(time.RFC3339), b.ModTime().Format(time.RFC3339))
r.Equal(a.Mode(), b.Mode())
r.Equal(a.Name(), b.Name())
r.Equal(a.Size(), b.Size())
}